From: Ian Rogers <irogers@google.com>
To: Yury Norov <yury.norov@gmail.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Arnd Bergmann <arnd@arndb.de>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Jakub Kicinski <kuba@kernel.org>,
Jacob Keller <jacob.e.keller@intel.com>,
linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, Leo Yan <leo.yan@arm.com>
Subject: [PATCH v2 1/5] bitfield: Silence a clang -Wshorten-64-to-32 warning
Date: Wed, 30 Apr 2025 10:15:30 -0700 [thread overview]
Message-ID: <20250430171534.132774-2-irogers@google.com> (raw)
In-Reply-To: <20250430171534.132774-1-irogers@google.com>
The clang warning -Wshorten-64-to-32 can be useful to catch
inadvertent truncation. In some instances this truncation can lead to
changing the sign of a result, for example, truncation to return an
int to fit a sort routine. Silence the warning by making the implicit
truncation explicit. This isn't to say the code is currently incorrect
but without silencing the warning it is hard to spot the erroneous
cases.
Signed-off-by: Ian Rogers <irogers@google.com>
---
include/linux/bitfield.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h
index 63928f173223..cc5cfed041bb 100644
--- a/include/linux/bitfield.h
+++ b/include/linux/bitfield.h
@@ -176,7 +176,7 @@ static __always_inline __##type type##_encode_bits(base v, base field) \
{ \
if (__builtin_constant_p(v) && (v & ~field_mask(field))) \
__field_overflow(); \
- return to((v & field_mask(field)) * field_multiplier(field)); \
+ return to((__##type)((v & field_mask(field)) * field_multiplier(field))); \
} \
static __always_inline __##type type##_replace_bits(__##type old, \
base val, base field) \
--
2.49.0.906.g1f30a19c02-goog
next prev parent reply other threads:[~2025-04-30 17:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-30 17:15 [PATCH v2 0/5] Silence some clang -Wshorten-64-to-32 warnings Ian Rogers
2025-04-30 17:15 ` Ian Rogers [this message]
2025-05-03 10:33 ` [PATCH v2 1/5] bitfield: Silence a clang -Wshorten-64-to-32 warning David Laight
2025-05-07 8:38 ` kernel test robot
2025-04-30 17:15 ` [PATCH v2 2/5] bitmap: " Ian Rogers
2025-05-02 16:03 ` Yury Norov
2025-05-02 16:43 ` Ian Rogers
2025-05-02 16:55 ` Yury Norov
2025-05-02 17:13 ` Ian Rogers
2025-04-30 17:15 ` [PATCH v2 3/5] bitops: " Ian Rogers
2025-04-30 17:15 ` [PATCH v2 4/5] math64: " Ian Rogers
2025-05-01 20:07 ` David Laight
2025-05-01 20:15 ` Ian Rogers
2025-05-01 20:26 ` David Laight
2025-05-01 21:11 ` Ian Rogers
2025-05-02 12:17 ` David Laight
2025-04-30 17:15 ` [PATCH v2 5/5] hash.h: " Ian Rogers
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=20250430171534.132774-2-irogers@google.com \
--to=irogers@google.com \
--cc=adrian.hunter@intel.com \
--cc=arnd@arndb.de \
--cc=jacob.e.keller@intel.com \
--cc=justinstitt@google.com \
--cc=kuba@kernel.org \
--cc=leo.yan@arm.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=tglx@linutronix.de \
--cc=yury.norov@gmail.com \
/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