From: Bart Van Assche <bvanassche@acm.org>
commit 92d23c6e94157739b997cacce151586a0d07bb8a upstream.
There are two definitions of the is_signed_type() macro: one in
<linux/overflow.h> and a second definition in <linux/trace_events.h>.
As suggested by Linus, move the definition of the is_signed_type() macro
into the <linux/compiler.h> header file. Change the definition of the
is_signed_type() macro to make sure that it does not trigger any sparse
warnings with future versions of sparse for bitwise types.
Link: https://lore.kernel.org/all/CAHk-=whjH6p+qzwUdx5SOVVHjS3WvzJQr6mDUwhEyTf6pJWzaQ@mail.gmail.com/
Link: https://lore.kernel.org/all/CAHk-=wjQGnVfb4jehFR0XyZikdQvCZouE96xR_nnf5kqaM5qqQ@mail.gmail.com/
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit a49a64b5bf195381c09202c524f0f84b5f3e816f)
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
include/linux/compiler.h | 6 ++++++
include/linux/overflow.h | 1 -
include/linux/trace_events.h | 2 --
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index bbd74420fa21..004a030d5ad2 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -245,6 +245,12 @@ static inline void *offset_to_ptr(const int *off)
/* &a[0] degrades to a pointer: a different type from an array */
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
+/*
+ * 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)
+
/*
* This is needed in functions which generate the stack canary, see
* arch/x86/kernel/smpboot.c::start_secondary() for an example.
diff --git a/include/linux/overflow.h b/include/linux/overflow.h
index 35af574d006f..66dd311ad8eb 100644
--- a/include/linux/overflow.h
+++ b/include/linux/overflow.h
@@ -32,7 +32,6 @@
* https://mail-index.netbsd.org/tech-misc/2007/02/05/0000.html -
* credit to Christian Biere.
*/
-#define is_signed_type(type) (((type)(-1)) < (type)1)
#define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type)))
#define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T)))
#define type_min(T) ((T)((T)-type_max(T)-(T)1))
diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 5af2acb9fb7d..0c8c3cf36f96 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -700,8 +700,6 @@ extern int trace_add_event_call(struct trace_event_call *call);
extern int trace_remove_event_call(struct trace_event_call *call);
extern int trace_event_get_offsets(struct trace_event_call *call);
-#define is_signed_type(type) (((type)(-1)) < (type)1)
-
int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
int trace_set_clr_event(const char *system, const char *event, int set);
int trace_array_set_clr_event(struct trace_array *tr, const char *system,
--
2.47.3
On Tue, Sep 16, 2025 at 09:22:53PM +0000, Eliav Farber wrote: > From: Bart Van Assche <bvanassche@acm.org> > > commit 92d23c6e94157739b997cacce151586a0d07bb8a upstream. This is only in 6.1, and not other trees, why is it needed here? > > There are two definitions of the is_signed_type() macro: one in > <linux/overflow.h> and a second definition in <linux/trace_events.h>. > > As suggested by Linus, move the definition of the is_signed_type() macro > into the <linux/compiler.h> header file. Change the definition of the > is_signed_type() macro to make sure that it does not trigger any sparse > warnings with future versions of sparse for bitwise types. > > Link: https://lore.kernel.org/all/CAHk-=whjH6p+qzwUdx5SOVVHjS3WvzJQr6mDUwhEyTf6pJWzaQ@mail.gmail.com/ > Link: https://lore.kernel.org/all/CAHk-=wjQGnVfb4jehFR0XyZikdQvCZouE96xR_nnf5kqaM5qqQ@mail.gmail.com/ > Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> > Cc: Steven Rostedt <rostedt@goodmis.org> > Acked-by: Kees Cook <keescook@chromium.org> > Signed-off-by: Bart Van Assche <bvanassche@acm.org> > Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> > (cherry picked from commit a49a64b5bf195381c09202c524f0f84b5f3e816f) This is not a valid git id in the tree at all. greg k-h
> On Tue, Sep 16, 2025 at 09:22:53PM +0000, Eliav Farber wrote: > > From: Bart Van Assche <bvanassche@acm.org> > > > > commit 92d23c6e94157739b997cacce151586a0d07bb8a upstream. > > This is only in 6.1, and not other trees, why is it needed here? It exists also in 5.15: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/include/linux/overflow.h?h=v5.15.193&id=ed6e37e30826b12572636c6bbfe6319233690c90 Without this change, I get many compilation errors when backporting commit d53b5d862acd ("minmax: allow min()/max()/clamp() if the arguments have the same signedness.") CALL scripts/atomic/check-atomics.sh CC arch/arm64/kernel/asm-offsets.s In file included from ./include/linux/bits.h:22, from ./include/linux/ioport.h:15, from ./include/linux/acpi.h:12, from ./include/acpi/apei.h:9, from ./include/acpi/ghes.h:5, from ./include/linux/arm_sdei.h:8, from arch/arm64/kernel/asm-offsets.c:10: ./include/linux/nodemask.h: In function '__first_node': ./include/linux/minmax.h:30:39: error: implicit declaration of function 'is_signed_type' [-Werror=implicit-function-declaration] 30 | __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))), \ | ^~~~~~~~~~~~~~ ./include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert' 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) | ^~~~ ./include/linux/minmax.h:50:3: note: in expansion of macro 'static_assert' 50 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~~~~ ./include/linux/minmax.h:30:24: note: in expansion of macro '__is_constexpr' 30 | __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))), \ | ^~~~~~~~~~~~~~ ./include/linux/minmax.h:38:3: note: in expansion of macro '__is_signed' 38 | (__is_signed(x) == __is_signed(y) || \ | ^~~~~~~~~~~ ./include/linux/minmax.h:50:17: note: in expansion of macro '__types_ok' 50 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~ ./include/linux/minmax.h:57:3: note: in expansion of macro '__cmp_once' 57 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ ./include/linux/minmax.h:160:27: note: in expansion of macro '__careful_cmp' 160 | #define min_t(type, x, y) __careful_cmp(min, (type)(x), (type)(y)) | ^~~~~~~~~~~~~ ./include/linux/nodemask.h:265:9: note: in expansion of macro 'min_t' 265 | return min_t(unsigned int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES)); | ^~~~~ ./include/linux/minmax.h:30:54: error: expected expression before 'typeof' 30 | __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))), \ | ^~~~~~ ./include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert' ... > > Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> (cherry > > picked from commit a49a64b5bf195381c09202c524f0f84b5f3e816f) > > This is not a valid git id in the tree at all. I will fix the mismatch here and above, but please notice that this hash appears in the link I shared. --- Regards, Eliav
On Wed, Sep 17, 2025 at 10:37:31AM +0000, Farber, Eliav wrote: > > On Tue, Sep 16, 2025 at 09:22:53PM +0000, Eliav Farber wrote: > > > From: Bart Van Assche <bvanassche@acm.org> > > > > > > commit 92d23c6e94157739b997cacce151586a0d07bb8a upstream. > > > > This is only in 6.1, and not other trees, why is it needed here? > > It exists also in 5.15: > https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/include/linux/overflow.h?h=v5.15.193&id=ed6e37e30826b12572636c6bbfe6319233690c90 What? Ugh, duplicate commit ids. What a mess :( Fair enough, I can take this, and I want to, but as this really causes a problem with our scripts, perhaps use the git id that is references in the other kernel versions as well so that things don't look totally wrong? thanks, greg k-h
© 2016 - 2025 Red Hat, Inc.