[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] x86/hvm: Rearange check_segment() to use a switch statement



commit 43dceb97eb3e45957c5a2e8a1ec874b9eb1ee941
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Mon Jun 5 17:19:27 2017 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Tue Jul 25 19:56:35 2017 +0100

    x86/hvm: Rearange check_segment() to use a switch statement
    
    This simplifies the logic by separating the x86_segment check from the type
    check.  No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/hvm/domain.c | 43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/xen/arch/x86/hvm/domain.c b/xen/arch/x86/hvm/domain.c
index dca7a00..293956c 100644
--- a/xen/arch/x86/hvm/domain.c
+++ b/xen/arch/x86/hvm/domain.c
@@ -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;
     }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.