linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Lemon <jonathan.lemon@gmail.com>
To: <linux-kernel@vger.kernel.org>
Cc: <netdev@vger.kernel.org>, <kernel-team@fb.com>
Subject: [PATCH] linux/log2.h: enclose macro arg in parens
Date: Tue, 23 Jun 2020 10:07:39 -0700	[thread overview]
Message-ID: <20200623170739.3151706-1-jonathan.lemon@gmail.com> (raw)

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


             reply	other threads:[~2020-06-23 17:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-23 17:07 Jonathan Lemon [this message]
2020-06-23 20:59 ` [PATCH] linux/log2.h: enclose macro arg in parens Jakub Kicinski

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=20200623170739.3151706-1-jonathan.lemon@gmail.com \
    --to=jonathan.lemon@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.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).