mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	David Laight <david.laight.linux@gmail.com>,
	Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH] compiler.h: Support 64-bit bitwise types in is_signed_type()
Date: Mon, 16 Nov 2026 14:26:25 -0800	[thread overview]
Message-ID: <4002a78c6bf1fa4fc96d089bd6a704bf77e2e060.1794867767.git.bvanassche@acm.org> (raw)

Replace -1 with -1LL in the definition of is_signed_type(type) to
prevent sparse from emitting "cast to restricted __le64" and
"restricted __le64 degrades to integer" warnings when evaluating
is_signed_type() on 64-bit __bitwise types such as __le64 (for example,
in tracepoint __field() macros in net/mac80211/trace.h).

Use a 64-bit all-ones constant (-1LL) rather than a 32-bit int (-1)
because sparse only permits casting a non-zero integer constant to a
__bitwise type and ordering it with '<' when the constant has all bits
set across the full bit width of the target type. Ensure that the
constant before the cast has 64 bits set so that sparse's
restricted_value() and can_order() checks succeed for 64-bit __bitwise
types on both 32-bit and 64-bit architectures.

Add a KUnit test case for is_signed_type(__le64) in
lib/tests/is_signed_type_kunit.c to exercise 64-bit __bitwise types.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 include/linux/compiler.h         | 2 +-
 lib/tests/is_signed_type_kunit.c | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index cb2f6050bdf7..2f133a7c3885 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -326,7 +326,7 @@ static inline void *offset_to_ptr(const int *off)
  * Whether 'type' is a signed type or an unsigned type. Supports scalar types,
  * bool and also pointer types.
  */
-#define is_signed_type(type) (((type)(-1)) < (__force type)1)
+#define is_signed_type(type) (((type)(-1LL)) < (__force type)1)
 #define is_unsigned_type(type) (!is_signed_type(type))
 
 /*
diff --git a/lib/tests/is_signed_type_kunit.c b/lib/tests/is_signed_type_kunit.c
index 88adbe813f3a..b9c8f7da45e9 100644
--- a/lib/tests/is_signed_type_kunit.c
+++ b/lib/tests/is_signed_type_kunit.c
@@ -18,6 +18,8 @@ enum signed_enum {
 
 static void is_signed_type_test(struct kunit *test)
 {
+	typedef __bitwise long long bitwise_long_long;
+
 	KUNIT_EXPECT_EQ(test, is_signed_type(bool), false);
 	KUNIT_EXPECT_EQ(test, is_signed_type(signed char), true);
 	KUNIT_EXPECT_EQ(test, is_signed_type(unsigned char), false);
@@ -27,7 +29,10 @@ static void is_signed_type_test(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, is_signed_type(long), true);
 	KUNIT_EXPECT_EQ(test, is_signed_type(unsigned long), false);
 	KUNIT_EXPECT_EQ(test, is_signed_type(long long), true);
+	KUNIT_EXPECT_EQ(test, is_signed_type(bitwise_long_long), true);
 	KUNIT_EXPECT_EQ(test, is_signed_type(unsigned long long), false);
+	KUNIT_EXPECT_EQ(test, is_signed_type(__be64), false);
+	KUNIT_EXPECT_EQ(test, is_signed_type(__le64), false);
 	KUNIT_EXPECT_EQ(test, is_signed_type(enum unsigned_enum), false);
 	KUNIT_EXPECT_EQ(test, is_signed_type(enum signed_enum), true);
 	KUNIT_EXPECT_EQ(test, is_signed_type(void *), false);

                 reply	other threads:[~2026-11-16 22:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4002a78c6bf1fa4fc96d089bd6a704bf77e2e060.1794867767.git.bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=david.laight.linux@gmail.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®