From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 2/3] x86/hvm: Rearange check_segment() to use a switch statement
Date: Fri, 30 Jun 2017 16:04:01 +0100 [thread overview]
Message-ID: <1498835042-22501-3-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1498835042-22501-1-git-send-email-andrew.cooper3@citrix.com>
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>
---
CC: Jan Beulich <JBeulich@suse.com>
---
xen/arch/x86/hvm/domain.c | 41 ++++++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/xen/arch/x86/hvm/domain.c b/xen/arch/x86/hvm/domain.c
index dca7a00..20a5294 100644
--- a/xen/arch/x86/hvm/domain.c
+++ b/xen/arch/x86/hvm/domain.c
@@ -70,24 +70,35 @@ 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");
- return -EINVAL;
+ 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;
+
+ default: /* -Werror=switch */
+ break;
}
return 0;
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-06-30 15:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-30 15:03 [PATCH 0/3] Improvements to struct semgent_register Andrew Cooper
2017-06-30 15:04 ` [PATCH 1/3] x86/emul: Introduce build time assertions for struct segment_register Andrew Cooper
2017-07-03 12:29 ` Jan Beulich
2017-07-03 13:05 ` Andrew Cooper
2017-07-03 13:32 ` Jan Beulich
2017-07-03 13:37 ` Andrew Cooper
2017-06-30 15:04 ` Andrew Cooper [this message]
2017-07-03 12:34 ` [PATCH 2/3] x86/hvm: Rearange check_segment() to use a switch statement Jan Beulich
2017-07-03 13:15 ` Andrew Cooper
2017-07-03 13:33 ` Jan Beulich
2017-07-03 13:58 ` Andrew Cooper
2017-07-03 14:05 ` Jan Beulich
2017-06-30 15:04 ` [PATCH 3/3] x86/emul: Drop segment_attributes_t Andrew Cooper
2017-07-03 12:50 ` Jan Beulich
2017-07-03 13:20 ` Andrew Cooper
2017-07-03 13:10 ` [PATCH 4/3] x86/svm: Drop svm_segment_register_t Andrew Cooper
2017-07-03 13:37 ` Jan Beulich
2017-07-03 13:39 ` Andrew Cooper
2017-07-03 14:10 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1498835042-22501-3-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).