[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260115211120.GD831050@noisy.programming.kicks-ass.net>
Date: Thu, 15 Jan 2026 22:11:20 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Thomas Gleixner <tglx@...nel.org>
Cc: kernel test robot <lkp@...el.com>, Ian Rogers <irogers@...gle.com>,
oe-kbuild-all@...ts.linux.dev, linux-kernel@...r.kernel.org,
x86@...nel.org, sparse@...isli.org, linux-sparse@...r.kernel.org,
Marco Elver <elver@...gle.com>
Subject: Re: [tip:timers/vdso 12/14] net/rds/ib_cm.c:96:35: sparse: sparse:
incorrect type in argument 1 (different modifiers)
On Thu, Jan 15, 2026 at 08:28:51PM +0100, Thomas Gleixner wrote:
> On Thu, Jan 15 2026 at 00:36, kernel test robot wrote:
>
> Cc+ sparse folks.
>
> > sparse warnings: (new ones prefixed by >>)
> >>> net/rds/ib_cm.c:96:35: sparse: sparse: incorrect type in argument 1 (different modifiers) @@ expected void * @@ got restricted __be64 const * @@
> > net/rds/ib_cm.c:96:35: sparse: expected void *
> > net/rds/ib_cm.c:96:35: sparse: got restricted __be64 const *
> > net/rds/ib_cm.c:103:27: sparse: sparse: incorrect type in argument 1 (different modifiers) @@ expected void * @@ got restricted __be64 const * @@
> > net/rds/ib_cm.c:103:27: sparse: expected void *
> > net/rds/ib_cm.c:103:27: sparse: got restricted __be64 const *
>
> After staring a while at it, it turns out that get_unaligned_t(), which
> uses __unqual_scalar_typeof() to get an unqualified type makes sparse
> unhappy when the data type is __be64 (or any other __beNN variant).
>
> __beNN is annotated with __attribute__((bitwise)) when sparse is invoked
> (#ifdef CHECKER). That allows sparse to detect incompatible math
> operations with __beNN variables.
>
Per:
https://git.kernel.org/pub/scm/devel/sparse/sparse-dev.git/commit/?id=dc9efe442b8949234a6599fdc94dc7221dd040e1
it seems Sparse now knows about __typeof_unqual__; and it looks like the
implementation does what you want here (although I've not tested it).
Something like so perhaps, which then mandates the very latest Sparse.
---
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 04487c9bd751..7e0583ceb49f 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -232,11 +232,8 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
/*
* Use __typeof_unqual__() when available.
- *
- * XXX: Remove test for __CHECKER__ once
- * sparse learns about __typeof_unqual__().
*/
-#if CC_HAS_TYPEOF_UNQUAL && !defined(__CHECKER__)
+#if CC_HAS_TYPEOF_UNQUAL || defined(__CHECKER__)
# define USE_TYPEOF_UNQUAL 1
#endif
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index d3318a3c2577..a37d832d99a8 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -569,6 +569,7 @@ struct ftrace_likely_data {
* __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
* non-scalar types unchanged.
*/
+#ifndef USE_TYPEOF_UNQUAL
/*
* Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
* is not type-compatible with 'signed char', and we define a separate case.
@@ -586,6 +587,9 @@ struct ftrace_likely_data {
__scalar_type_to_expr_cases(long), \
__scalar_type_to_expr_cases(long long), \
default: (x)))
+#else
+#define __unqual_scalar_typeof(x) __typeof_unqual__(x)
+#endif
/* Is this type a native word size -- useful for atomic operations */
#define __native_word(t) \
Powered by blists - more mailing lists