linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] linux/log2.h: enclose macro arg in parens
@ 2020-06-23 17:07 Jonathan Lemon
  2020-06-23 20:59 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Lemon @ 2020-06-23 17:07 UTC (permalink / raw)
  To: linux-kernel; +Cc: netdev, kernel-team

From: Jonathan Lemon <bsd@fb.com>

roundup_pow_of_two uses its arg without enclosing it in parens.

A call of the form:

   roundup_pow_of_two(boolval ? PAGE_SIZE : frag_size)

resulted in an compile warning:

warning: ?: using integer constants in boolean context [-Wint-in-bool-context]
              PAGE_SIZE :
../include/linux/log2.h:176:4: note: in definition of macro ‘roundup_pow_of_two’
   (n == 1) ? 1 :  \
    ^
And the resulting code used '1' as the result of the operation.

Fixes: 312a0c170945 ("[PATCH] LOG2: Alter roundup_pow_of_two() so that it can use a ilog2() on a constant")

Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
---
 include/linux/log2.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/log2.h b/include/linux/log2.h
index 83a4a3ca3e8a..c619ec6eff4a 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -173,7 +173,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
 #define roundup_pow_of_two(n)			\
 (						\
 	__builtin_constant_p(n) ? (		\
-		(n == 1) ? 1 :			\
+		((n) == 1) ? 1 :		\
 		(1UL << (ilog2((n) - 1) + 1))	\
 				   ) :		\
 	__roundup_pow_of_two(n)			\
-- 
2.24.1


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

* Re: [PATCH] linux/log2.h: enclose macro arg in parens
  2020-06-23 17:07 [PATCH] linux/log2.h: enclose macro arg in parens Jonathan Lemon
@ 2020-06-23 20:59 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2020-06-23 20:59 UTC (permalink / raw)
  To: Jonathan Lemon; +Cc: linux-kernel, netdev, kernel-team

On Tue, 23 Jun 2020 10:07:39 -0700 Jonathan Lemon wrote:
> From: Jonathan Lemon <bsd@fb.com>
> 
> roundup_pow_of_two uses its arg without enclosing it in parens.
> 
> A call of the form:
> 
>    roundup_pow_of_two(boolval ? PAGE_SIZE : frag_size)
> 
> resulted in an compile warning:
> 
> warning: ?: using integer constants in boolean context [-Wint-in-bool-context]
>               PAGE_SIZE :
> ../include/linux/log2.h:176:4: note: in definition of macro ‘roundup_pow_of_two’
>    (n == 1) ? 1 :  \
>     ^
> And the resulting code used '1' as the result of the operation.

I'd have thought that this warning is harmless, since the expression
clearly is not a constant, interesting.

> Fixes: 312a0c170945 ("[PATCH] LOG2: Alter roundup_pow_of_two() so that it can use a ilog2() on a constant")
> 

Please no empty line between fixes and other tags.

> Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com>
> ---
>  include/linux/log2.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/log2.h b/include/linux/log2.h
> index 83a4a3ca3e8a..c619ec6eff4a 100644
> --- a/include/linux/log2.h
> +++ b/include/linux/log2.h
> @@ -173,7 +173,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
>  #define roundup_pow_of_two(n)			\
>  (						\
>  	__builtin_constant_p(n) ? (		\
> -		(n == 1) ? 1 :			\
> +		((n) == 1) ? 1 :		\
>  		(1UL << (ilog2((n) - 1) + 1))	\
>  				   ) :		\
>  	__roundup_pow_of_two(n)			\


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

end of thread, other threads:[~2020-06-23 21:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 17:07 [PATCH] linux/log2.h: enclose macro arg in parens Jonathan Lemon
2020-06-23 20:59 ` Jakub Kicinski

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).