diff mbox

[2/3] x86: fix build with gcc 7

Message ID 591D7A31020000780015AC01@prv-mh.provo.novell.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Beulich May 18, 2017, 8:40 a.m. UTC
-Wint-in-bool-context, enabled by default in gcc 7, doesn't like
multiplication in conditional operators. "Hide" them, at the risk of
the next compiler version becoming smarter and recognizing even those.
(The hope is that added smartness then would also better deal with
legitimate cases like the ones here.)

The change could have been done in access_ok(), but I think we better
keep it at the places the compiler is actually unhappy about.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
x86: fix build with gcc 7

-Wint-in-bool-context, enabled by default in gcc 7, doesn't like
multiplication in conditional operators. "Hide" them, at the risk of
the next compiler version becoming smarter and recognizing even those.
(The hope is that added smartness then would also better deal with
legitimate cases like the ones here.)

The change could have been done in access_ok(), but I think we better
keep it at the places the compiler is actually unhappy about.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -3318,7 +3318,7 @@ static void emulate_gate_op(struct cpu_u
                 return;
             }
             stkp = (unsigned int *)(unsigned long)((unsigned int)base + esp);
-            if ( !compat_access_ok(stkp - 4 - nparm, (4 + nparm) * 4) )
+            if ( !compat_access_ok(stkp - 4 - nparm, 16 + nparm * 4) )
             {
                 do_guest_trap(TRAP_gp_fault, regs);
                 return;
@@ -3338,7 +3338,7 @@ static void emulate_gate_op(struct cpu_u
                     return do_guest_trap(TRAP_gp_fault, regs);
                 ustkp = (unsigned int *)(unsigned long)
                         ((unsigned int)base + regs->esp + nparm * 4);
-                if ( !compat_access_ok(ustkp - nparm, nparm * 4) )
+                if ( !compat_access_ok(ustkp - nparm, 0 + nparm * 4) )
                 {
                     do_guest_trap(TRAP_gp_fault, regs);
                     return;
--- a/xen/include/asm-x86/x86_64/uaccess.h
+++ b/xen/include/asm-x86/x86_64/uaccess.h
@@ -42,7 +42,7 @@ extern void *xlat_malloc(unsigned long *
 
 #define array_access_ok(addr, count, size) \
     (likely(((count) ?: 0UL) < (~0UL / (size))) && \
-     access_ok(addr, (count) * (size)))
+     access_ok(addr, 0 + (count) * (size)))
 
 #define __compat_addr_ok(d, addr) \
     ((unsigned long)(addr) < HYPERVISOR_COMPAT_VIRT_START(d))
@@ -55,7 +55,7 @@ extern void *xlat_malloc(unsigned long *
 
 #define compat_array_access_ok(addr,count,size) \
     (likely((count) < (~0U / (size))) && \
-     compat_access_ok(addr, (count) * (size)))
+     compat_access_ok(addr, 0 + (count) * (size)))
 
 #define __put_user_size(x,ptr,size,retval,errret)			\
 do {									\

Comments

Andrew Cooper May 18, 2017, 10:18 a.m. UTC | #1
On 18/05/17 09:40, Jan Beulich wrote:
> -Wint-in-bool-context, enabled by default in gcc 7, doesn't like
> multiplication in conditional operators. "Hide" them, at the risk of
> the next compiler version becoming smarter and recognizing even those.
> (The hope is that added smartness then would also better deal with
> legitimate cases like the ones here.)
>
> The change could have been done in access_ok(), but I think we better
> keep it at the places the compiler is actually unhappy about.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
diff mbox

Patch

--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -3318,7 +3318,7 @@  static void emulate_gate_op(struct cpu_u
                 return;
             }
             stkp = (unsigned int *)(unsigned long)((unsigned int)base + esp);
-            if ( !compat_access_ok(stkp - 4 - nparm, (4 + nparm) * 4) )
+            if ( !compat_access_ok(stkp - 4 - nparm, 16 + nparm * 4) )
             {
                 do_guest_trap(TRAP_gp_fault, regs);
                 return;
@@ -3338,7 +3338,7 @@  static void emulate_gate_op(struct cpu_u
                     return do_guest_trap(TRAP_gp_fault, regs);
                 ustkp = (unsigned int *)(unsigned long)
                         ((unsigned int)base + regs->esp + nparm * 4);
-                if ( !compat_access_ok(ustkp - nparm, nparm * 4) )
+                if ( !compat_access_ok(ustkp - nparm, 0 + nparm * 4) )
                 {
                     do_guest_trap(TRAP_gp_fault, regs);
                     return;
--- a/xen/include/asm-x86/x86_64/uaccess.h
+++ b/xen/include/asm-x86/x86_64/uaccess.h
@@ -42,7 +42,7 @@  extern void *xlat_malloc(unsigned long *
 
 #define array_access_ok(addr, count, size) \
     (likely(((count) ?: 0UL) < (~0UL / (size))) && \
-     access_ok(addr, (count) * (size)))
+     access_ok(addr, 0 + (count) * (size)))
 
 #define __compat_addr_ok(d, addr) \
     ((unsigned long)(addr) < HYPERVISOR_COMPAT_VIRT_START(d))
@@ -55,7 +55,7 @@  extern void *xlat_malloc(unsigned long *
 
 #define compat_array_access_ok(addr,count,size) \
     (likely((count) < (~0U / (size))) && \
-     compat_access_ok(addr, (count) * (size)))
+     compat_access_ok(addr, 0 + (count) * (size)))
 
 #define __put_user_size(x,ptr,size,retval,errret)			\
 do {									\