Message ID | 165d61fab77c0b6613b78e0091195753fe9cd2cc.1712305581.git.nicola.vetrini@bugseng.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | address violations of MISRA C Rule 16.2 | expand |
On 05.04.2024 11:14, Nicola Vetrini wrote: > --- a/xen/arch/x86/hvm/hypercall.c > +++ b/xen/arch/x86/hvm/hypercall.c > @@ -119,12 +119,12 @@ int hvm_hypercall(struct cpu_user_regs *regs) > (mode == 8 ? regs->rdi : regs->ebx) == HVMOP_guest_request_vm_event ) > break; > > - if ( unlikely(hvm_get_cpl(curr)) ) > - { > + if ( !unlikely(hvm_get_cpl(curr)) ) likely() / unlikely() want to be the outermost part of a conditional like this (things are different with && or ||), i.e. if ( likely(!hvm_get_cpl(curr)) ) Then: Acked-by: Jan Beulich <jbeulich@suse.com> Jan
On 2024-04-08 09:57, Jan Beulich wrote: > On 05.04.2024 11:14, Nicola Vetrini wrote: >> --- a/xen/arch/x86/hvm/hypercall.c >> +++ b/xen/arch/x86/hvm/hypercall.c >> @@ -119,12 +119,12 @@ int hvm_hypercall(struct cpu_user_regs *regs) >> (mode == 8 ? regs->rdi : regs->ebx) == >> HVMOP_guest_request_vm_event ) >> break; >> >> - if ( unlikely(hvm_get_cpl(curr)) ) >> - { >> + if ( !unlikely(hvm_get_cpl(curr)) ) > > likely() / unlikely() want to be the outermost part of a conditional > like this (things are different with && or ||), i.e. > > if ( likely(!hvm_get_cpl(curr)) ) > Ok, LGTM > Then: > Acked-by: Jan Beulich <jbeulich@suse.com> > > Jan
diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index eeb73e1aa5d0..2801d75d89f1 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -119,12 +119,12 @@ int hvm_hypercall(struct cpu_user_regs *regs) (mode == 8 ? regs->rdi : regs->ebx) == HVMOP_guest_request_vm_event ) break; - if ( unlikely(hvm_get_cpl(curr)) ) - { + if ( !unlikely(hvm_get_cpl(curr)) ) + break; + fallthrough; default: - regs->rax = -EPERM; - return HVM_HCALL_completed; - } + regs->rax = -EPERM; + return HVM_HCALL_completed; case 0: break; }
Refactor the switch so that a violation of MISRA C Rule 16.2 is resolved (a switch label should be immediately enclosed in the compound statement of the switch). The switch clause ending with the pseudo keyword "fallthrough" is an allowed exception to Rule 16.3. Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com> --- xen/arch/x86/hvm/hypercall.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)