All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] minios: Fix incorrect {, un}likely() definitions
@ 2014-06-30 15:57 Andrew Cooper
  2014-06-30 16:00 ` Samuel Thibault
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Cooper @ 2014-06-30 15:57 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Samuel Thibault, Stefano Stabellini

As identified in e5545fb6, likely() and unlikely() must convert their
expressions to booleans before comparing to 1 or 0, to avoid truncation
issues.

While editing this file, add inclusion guards.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
CC: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 extras/mini-os/include/compiler.h |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/extras/mini-os/include/compiler.h b/extras/mini-os/include/compiler.h
index e35c9d5..4188277 100644
--- a/extras/mini-os/include/compiler.h
+++ b/extras/mini-os/include/compiler.h
@@ -1,5 +1,10 @@
+#ifndef __MINIOS_COMPILER_H_
+#define __MINIOS_COMPILER_H_
+
 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
 #define __builtin_expect(x, expected_value) (x)
 #endif
-#define unlikely(x)  __builtin_expect((x),0)
-#define likely(x)  __builtin_expect((x),1)
+#define unlikely(x)  __builtin_expect(!!(x),0)
+#define likely(x)    __builtin_expect(!!(x),1)
+
+#endif /* __MINIOS_COMPILER_H_ */
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] minios: Fix incorrect {, un}likely() definitions
  2014-06-30 15:57 [PATCH] minios: Fix incorrect {, un}likely() definitions Andrew Cooper
@ 2014-06-30 16:00 ` Samuel Thibault
  0 siblings, 0 replies; 2+ messages in thread
From: Samuel Thibault @ 2014-06-30 16:00 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Stefano Stabellini, Xen-devel

Andrew Cooper, le Mon 30 Jun 2014 16:57:15 +0100, a écrit :
> As identified in e5545fb6, likely() and unlikely() must convert their
> expressions to booleans before comparing to 1 or 0, to avoid truncation
> issues.
> 
> While editing this file, add inclusion guards.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> CC: Samuel Thibault <samuel.thibault@ens-lyon.org>

Acked-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  extras/mini-os/include/compiler.h |    9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/extras/mini-os/include/compiler.h b/extras/mini-os/include/compiler.h
> index e35c9d5..4188277 100644
> --- a/extras/mini-os/include/compiler.h
> +++ b/extras/mini-os/include/compiler.h
> @@ -1,5 +1,10 @@
> +#ifndef __MINIOS_COMPILER_H_
> +#define __MINIOS_COMPILER_H_
> +
>  #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
>  #define __builtin_expect(x, expected_value) (x)
>  #endif
> -#define unlikely(x)  __builtin_expect((x),0)
> -#define likely(x)  __builtin_expect((x),1)
> +#define unlikely(x)  __builtin_expect(!!(x),0)
> +#define likely(x)    __builtin_expect(!!(x),1)
> +
> +#endif /* __MINIOS_COMPILER_H_ */
> -- 
> 1.7.10.4
> 

-- 
Samuel
> No manual is ever necessary.
May I politely interject here: BULLSHIT.  That's the biggest Apple lie of all!
(Discussion in comp.os.linux.misc on the intuitiveness of interfaces.)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-30 16:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-30 15:57 [PATCH] minios: Fix incorrect {, un}likely() definitions Andrew Cooper
2014-06-30 16:00 ` Samuel Thibault

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.