x86/traps: Misc non-functional improvements to set_debugreg()

* Change 'int i' to being unsigned, and move it into its most narrow scope.
 * Fold the access_ok() checks for %dr{0..3}.  This halves the compiled size
   of the function.
 * Additional newlines in appropriate places.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
This commit is contained in:
Andrew Cooper committed 2018-04-17 15:12:36 +01:00
1 parent f539ae2706
commit a50238afa9
1 file changed
+13 -22
+13 -22
View File
@@ -2006,34 +2006,24 @@ void activate_debugregs(const struct vcpu *curr)
*/
long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
{
int i;
struct vcpu *curr = current;
switch ( reg )
{
case 0:
case 0 ... 3:
if ( !access_ok(value, sizeof(long)) )
return -EPERM;
if ( v == curr )
write_debugreg(0, value);
break;
case 1:
if ( !access_ok(value, sizeof(long)) )
return -EPERM;
if ( v == curr )
write_debugreg(1, value);
break;
case 2:
if ( !access_ok(value, sizeof(long)) )
return -EPERM;
if ( v == curr )
write_debugreg(2, value);
break;
case 3:
if ( !access_ok(value, sizeof(long)) )
return -EPERM;
if ( v == curr )
write_debugreg(3, value);
{
switch ( reg )
{
case 0: write_debugreg(0, value); break;
case 1: write_debugreg(1, value); break;
case 2: write_debugreg(2, value); break;
case 3: write_debugreg(3, value); break;
}
}
break;
case 4:
@@ -2085,7 +2075,7 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
/* DR7.{G,L}E = 0 => debugging disabled for this domain. */
if ( value & DR7_ACTIVE_MASK )
{
unsigned int io_enable = 0;
unsigned int i, io_enable = 0;
for ( i = DR_CONTROL_SHIFT; i < 32; i += DR_CONTROL_SIZE )
{
@@ -2113,6 +2103,7 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)
if ( v == curr )
write_debugreg(7, value);
break;
default:
return -ENODEV;
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.