mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] tracing: Make is_signed_type() compatible with sparse
@ 2026-08-07 17:00 Bart Van Assche
  2026-08-31  0:20 ` Bart Van Assche
  2026-08-31 20:44 ` David Laight
  0 siblings, 2 replies; 36+ messages in thread
From: Bart Van Assche @ 2026-08-07 17:00 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: linux-kernel, Bart Van Assche, Christoph Hellwig,
	Rasmus Villemoes, Luc Van Oostenryck, Linus Torvalds, Chris Li

Using a __bitwise type in a tracing __field() definition triggers four
sparse warnings in stage 4 of expanding the TRACE_EVENT() macro. These
warnings are triggered by the is_signed_type() macro implementation.
Fix this by using _Generic() in the is_signed_type() implementation
instead of an integer comparison.

An earlier attempt to fix this issue is available here:
https://lore.kernel.org/all/20220717151047.19220-1-bvanassche@acm.org/

Cc: Christoph Hellwig <hch@lst.de>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---

Changes compared to v1: removed #ifdef __CHECKER__.

 include/linux/compiler.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index cb2f6050bdf7..ba9c7e16802d 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -326,7 +326,14 @@ 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) _Generic((type)0,	\
+	signed char: true,			\
+	signed short: true,			\
+	signed int: true,			\
+	signed long: true,			\
+	signed long long: true,			\
+	char: ((char)-1 < (char)1),		\
+	default: false)
 #define is_unsigned_type(type) (!is_signed_type(type))
 
 /*

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

end of thread, other threads:[~2026-09-05  7:48 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-07 17:00 [PATCH v2] tracing: Make is_signed_type() compatible with sparse Bart Van Assche
2026-08-31  0:20 ` Bart Van Assche
2026-08-31 14:27   ` Steven Rostedt
2026-08-31 20:44 ` David Laight
2026-08-31 21:19   ` Bart Van Assche
2026-09-01  8:20     ` David Laight
2026-09-01 18:05       ` Bart Van Assche
2026-09-01 18:45         ` Linus Torvalds
2026-09-01 19:22           ` Bart Van Assche
2026-09-01 19:35             ` Linus Torvalds
2026-09-01 19:38               ` Linus Torvalds
2026-09-01 20:06               ` Bart Van Assche
2026-09-01 20:24                 ` Linus Torvalds
2026-09-01 22:46                   ` Bart Van Assche
2026-09-05  7:48                     ` Uwe Kleine-König
2026-09-01 21:29         ` David Laight
2026-09-01 21:43           ` Bart Van Assche
2026-09-01 21:56             ` Linus Torvalds
2026-09-01 23:25               ` Steven Rostedt
2026-09-02  8:24                 ` David Laight
2026-09-02 13:36                   ` Steven Rostedt
2026-09-02 15:16                     ` David Laight
2026-09-02 16:31                     ` Bart Van Assche
2026-09-02 16:39                       ` Steven Rostedt
2026-09-02 16:44                         ` Bart Van Assche
2026-09-02 16:54                           ` Steven Rostedt
2026-09-02 17:04                             ` Linus Torvalds
2026-09-02 17:24                               ` Steven Rostedt
2026-09-02 18:06                           ` David Laight
2026-09-02 18:21                             ` Steven Rostedt
2026-09-02 20:50                               ` David Laight
2026-09-02 22:40                                 ` Bart Van Assche
2026-09-02 22:43                                 ` Linus Torvalds
2026-09-02 16:52                         ` Linus Torvalds
2026-09-03 21:50                 ` Vincent Mailhol
2026-09-04  0:26                   ` Steven Rostedt

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®