Skip to contentSkip to conversation

compiler_typesh-fix-unused-variable-in-__compiletime_assert.patch removed from -mm tree

merged mm-nonmm-stable Andrew Morton 1 participant 1 message May 12, 2025

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: compiler_types.h: fix "unused variable" in __compiletime_assert()
has been removed from the -mm tree. Its filename was
compiler_typesh-fix-unused-variable-in-__compiletime_assert.patch

This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Marc Herbert <[email protected]>
Subject: compiler_types.h: fix "unused variable" in __compiletime_assert()
Date: Thu, 24 Apr 2025 19:40:35 +0000

This refines commit c03567a8e8d5 ("include/linux/compiler.h: don't perform compiletime_assert with -O0") and restores #ifdef __OPTIMIZE__ symmetry by evaluating the 'condition' variable in both compile-time variants of __compiletimeassert().

As __OPTIMIZE__ is always true by default, this commit does not change anything by default. But it fixes warnings with _non-default_ CFLAGS like for instance this:

make CFLAGS_tcp.o='-Og -U__OPTIMIZE__'

                 from net/ipv4/tcp.c:273:

include/net/sch_generic.h: In function `qdisc_cb_private_validate':
include/net/sch_generic.h:511:30:
error: unused variable `qcb' [-Werror=unused-variable]

  {
     struct qdisc_skb_cb *qcb;
     BUILD_BUG_ON(sizeof(skb->cb) < sizeof(*qcb));
     ...

}

[[email protected]: regularize comment layout, reflow comment]
Cc Alexander Potapenko <[email protected]>
Cc Changbin Du <[email protected]>
Cc Jan Hendrik Farr <[email protected]>
Cc Macro Elver <[email protected]>
Cc Miguel Ojeda <[email protected]>
Cc Tony Ambardar <[email protected]>
Cc Uros Bizjak <[email protected]>
Cc Kees Cook <[email protected]>

---

 include/linux/compiler_types.h |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
include/linux/compiler_types.h renamed from include/linux/compiler_types.h~compiler_typesh-fix-unused-variable-in-__compiletime_assert +7 -1
@@ -525,6 +525,12 @@ struct ftrace_likely_data {
 	 sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
 
 #ifdef __OPTIMIZE__
+/*
+ * #ifdef __OPTIMIZE__ is only a good approximation; for instance "make
+ * CFLAGS_foo.o=-Og" defines __OPTIMIZE__, does not elide the conditional code
+ * and can break compilation with wrong error message(s). Combine with
+ * -U__OPTIMIZE__ when needed.
+ */
 # define __compiletime_assert(condition, msg, prefix, suffix)		\
 	do {								\
 		/*							\
@@ -538,7 +544,7 @@ struct ftrace_likely_data {
 			prefix ## suffix();				\
 	} while (0)
 #else
-# define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)
+# define __compiletime_assert(condition, msg, prefix, suffix) ((void)(condition))
 #endif
 
 #define _compiletime_assert(condition, msg, prefix, suffix) \

_

Patches currently in -mm which might be from [email protected] are