]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
x86/hvm: Rearange check_segment() to use a switch statement
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 5 Jun 2017 16:19:27 +0000 (17:19 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 25 Jul 2017 18:56:35 +0000 (19:56 +0100)
This simplifies the logic by separating the x86_segment check from the type
check.  No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/hvm/domain.c

index dca7a0086e2fcc3f7c3b10f49c5fd4bc86154171..293956cdad843b572052e5bbc4adb5367ed3b1a2 100644 (file)
@@ -70,23 +70,38 @@ static int check_segment(struct segment_register *reg, enum x86_segment seg)
         return -EINVAL;
     }
 
-    if ( seg == x86_seg_cs && !(reg->attr.fields.type & 0x8) )
+    switch ( seg )
     {
-        gprintk(XENLOG_ERR, "Non-code segment provided for CS\n");
-        return -EINVAL;
-    }
+    case x86_seg_cs:
+        if ( !(reg->attr.fields.type & 0x8) )
+        {
+            gprintk(XENLOG_ERR, "Non-code segment provided for CS\n");
+            return -EINVAL;
+        }
+        break;
 
-    if ( seg == x86_seg_ss &&
-         ((reg->attr.fields.type & 0x8) || !(reg->attr.fields.type & 0x2)) )
-    {
-        gprintk(XENLOG_ERR, "Non-writeable segment provided for SS\n");
-        return -EINVAL;
-    }
+    case x86_seg_ss:
+        if ( (reg->attr.fields.type & 0x8) || !(reg->attr.fields.type & 0x2) )
+        {
+            gprintk(XENLOG_ERR, "Non-writeable segment provided for SS\n");
+            return -EINVAL;
+        }
+        break;
 
-    if ( reg->attr.fields.s && seg != x86_seg_ss && seg != x86_seg_cs &&
-         (reg->attr.fields.type & 0x8) && !(reg->attr.fields.type & 0x2) )
-    {
-        gprintk(XENLOG_ERR, "Non-readable segment provided for DS or ES\n");
+    case x86_seg_ds:
+    case x86_seg_es:
+        if ( (reg->attr.fields.type & 0x8) && !(reg->attr.fields.type & 0x2) )
+        {
+            gprintk(XENLOG_ERR, "Non-readable segment provided for DS or ES\n");
+            return -EINVAL;
+        }
+        break;
+
+    case x86_seg_tr:
+        break;
+
+    default:
+        ASSERT_UNREACHABLE();
         return -EINVAL;
     }