All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH next v2 0/5] minmax: Relax type checks in min() and max().
@ 2023-07-28 14:49 David Laight
  2023-07-28 14:50 ` [PATCH next v2 1/5] minmax: Add min_unsigned(a, b) and max_unsigned(a, b) David Laight
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: David Laight @ 2023-07-28 14:49 UTC (permalink / raw)
  To: 'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld'

The min() (etc) functions in minmax.h require that the arguments have
exactly the same types. This was probably added after an 'accident'
where a negative value got converted to a large unsigned value.

However when the type check fails, rather than look at the types and
fix the type of a variable/constant, everyone seems to jump on min_t().
In reality min_t() ought to be rare - when something unusual is being
done, not normality.
If the wrong type is picked (and it is far too easy to pick the type
of the result instead of the larger input) then significant bits can
get discarded.
Pretty much the worst example is in the derfved clamp_val(), consider:
	unsigned char x = 200u;
	y = clamp_val(x, 10u, 300u);

I also suspect that many of the min_t(u16, ...) are actually wrong.
For example copy_data() in printk_ringbuffer.c contains:
	data_size = min_t(u16, buf_size, len);
Here buf_size is 'unsigned int' and len 'u16', pass a 64k buffer
(can you prove that doesn't happen?) and no data is returned.

The only reason that most of the min_t() are 'fine' is that pretty
much all the value in the kernel are between 0 and INT_MAX.

Patch 1 adds min_unsigned(), this uses integer promotions to convert
both arguments to 'unsigned long long'. It can be used to compare a
signed type that is known to contain a non-negative value with an
unsigned type. The compiler typically optimises it all away.
Added first so that it can be referred to in patch 2.

Patch 2 replaces the 'same type' check with a 'same signedness' one.
This makes min(unsigned_int_var, sizeof()) be ok.
The error message is also improved and will contain the expanded
form of both arguments (useful for seeing how constants are defined).

Patch 3 just fixes some whitespace.

Patch 4 allows comparisons of 'unsigned char' and 'unsigned short'
to signed types. The integer promotion rules convert them both
to 'signed int' prior to the comparison so they can never cause
a negative value be converted to a large positive one.

Patch 5 is slightly more contentious (Linus may not like it!)
effectively adds an (int) cast to all constants between 0 and MAX_INT.
This makes min(signed_int_var, sizeof()) be ok.

With all the patches applied pretty much all the min_t() could be
replaced by min(), and most of the rest by min_unsigned().
However they all need careful inspection due to code like:
	sz = min_t(unsigned char, sz - 1, LIM - 1) + 1;
which converts 0 to LIM.

v2 Fixes some issues found by the kernel build robot.
No functional changes.

David Laight (5):
  Add min_unsigned(a, b) and max_unsigned(a, b)
  Allow min()/max()/clamp() if the arguments have the same signedness.
  Fix indentation of __cmp_once() and __clamp_once()
  Allow comparisons of 'int' against 'unsigned char/short'.
  Relax check to allow comparison between int and small unsigned
    constants.

 include/linux/minmax.h | 98 ++++++++++++++++++++++++++----------------
 1 file changed, 61 insertions(+), 37 deletions(-)

-- 
2.17.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* [PATCH next v2 1/5] minmax: Add min_unsigned(a, b) and max_unsigned(a, b)
  2023-07-28 14:49 [PATCH next v2 0/5] minmax: Relax type checks in min() and max() David Laight
@ 2023-07-28 14:50 ` David Laight
  2023-07-28 14:51 ` [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness David Laight
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: David Laight @ 2023-07-28 14:50 UTC (permalink / raw)
  To: 'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld'

These can be used when min()/max() errors a signed v unsigned
compare when the signed value is known to be non-negative.

Unlike min_t(some_unsigned_type, a, b) min_unsigned() will never
mask off high bits if an inappropriate type is selected.

The '+ 0u + 0ul + 0ull' may look strange.
The '+ 0u' is needed for 'signed int' on 64bit systems.
The '+ 0ul' is needed for 'signed long' on 32bit systems.
The '+ 0ull' is needed for 'signed long long'.

Signed-off-by: David Laight <david.laight@aculab.com>
---
v2: Updated commit message.
 include/linux/minmax.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 396df1121bff..531860e9cc55 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -73,6 +73,23 @@
  */
 #define max(x, y)	__careful_cmp(x, y, >)
 
+/**
+ * min_unsigned - return minimum of two non-negative values
+ *   Signed types are zero extended to match a larger unsigned type.
+ * @x: first value
+ * @y: second value
+ */
+#define min_unsigned(x, y)	\
+	__careful_cmp((x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull, <)
+
+/**
+ * max_unsigned - return maximum of two non-negative values
+ * @x: first value
+ * @y: second value
+ */
+#define max_unsigned(x, y)	\
+	__careful_cmp((x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull, >)
+
 /**
  * min3 - return minimum of three values
  * @x: first value
-- 
2.17.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.
  2023-07-28 14:49 [PATCH next v2 0/5] minmax: Relax type checks in min() and max() David Laight
  2023-07-28 14:50 ` [PATCH next v2 1/5] minmax: Add min_unsigned(a, b) and max_unsigned(a, b) David Laight
@ 2023-07-28 14:51 ` David Laight
  2023-07-29  2:00   ` kernel test robot
  2023-07-31 21:43   ` kernel test robot
  2023-07-28 14:52 ` [PATCH next v2 3/5] minmax: Fix indentation of __cmp_once() and __clamp_once() David Laight
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 16+ messages in thread
From: David Laight @ 2023-07-28 14:51 UTC (permalink / raw)
  To: 'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld'

The type-check in min()/max() is there to stop unexpected results if a
negative value gets converted to a large unsigned value.
However it also rejects 'unsigned int' v 'unsigned long' compares
which are common and never problematc.

Replace the 'same type' check with a 'same signedness' check.

The new test isn't itself a compile time error, so use static_assert()
to report the error and give a meaningful error message.

Due to the way builtin_choose_expr() works detecting the error in the
'non-constant' side (where static_assert() can be used) also detects
errors when the arguments are constant.

Signed-off-by: David Laight <david.laight@aculab.com>
---
Changes for v2:
- #include <linux/build_bug.h> to fix 'um' build.
  This matches a separate commit from Andy.
- Do not delete __typecheck() - used outside this file.
- Use __builtin_choose_expr() in __clamp_once() to fix clang builds.

 include/linux/minmax.h | 60 +++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 531860e9cc55..cb126853f2be 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -2,6 +2,7 @@
 #ifndef _LINUX_MINMAX_H
 #define _LINUX_MINMAX_H
 
+#include <linux/build_bug.h>
 #include <linux/const.h>
 
 /*
@@ -9,9 +10,8 @@
  *
  * - avoid multiple evaluations of the arguments (so side-effects like
  *   "x++" happen only once) when non-constant.
- * - perform strict type-checking (to generate warnings instead of
- *   nasty runtime surprises). See the "unnecessary" pointer comparison
- *   in __typecheck().
+ * - perform signed v unsigned type-checking (to generate compile
+ *   errors instead of nasty runtime surprises).
  * - retain result as a constant expressions when called with only
  *   constant expressions (to avoid tripping VLA warnings in stack
  *   allocation usage).
@@ -19,23 +19,25 @@
 #define __typecheck(x, y) \
 	(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
 
-#define __no_side_effects(x, y) \
-		(__is_constexpr(x) && __is_constexpr(y))
+#define __types_ok(x, y) \
+	(is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
 
-#define __safe_cmp(x, y) \
-		(__typecheck(x, y) && __no_side_effects(x, y))
+#define __cmp_op_min <
+#define __cmp_op_max >
 
-#define __cmp(x, y, op)	((x) op (y) ? (x) : (y))
+#define __cmp(op, x, y)	((x) __cmp_op_##op (y) ? (x) : (y))
 
-#define __cmp_once(x, y, unique_x, unique_y, op) ({	\
+#define __cmp_once(op, x, y, unique_x, unique_y) ({	\
 		typeof(x) unique_x = (x);		\
 		typeof(y) unique_y = (y);		\
-		__cmp(unique_x, unique_y, op); })
+		static_assert(__types_ok(x, y),		\
+			#op "(" #x ", " #y ") signedness error, fix types or consider " #op "_unsigned() before " #op "_t()"); \
+		__cmp(op, unique_x, unique_y); })
 
-#define __careful_cmp(x, y, op) \
-	__builtin_choose_expr(__safe_cmp(x, y), \
-		__cmp(x, y, op), \
-		__cmp_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y), op))
+#define __careful_cmp(op, x, y)					\
+	__builtin_choose_expr(__is_constexpr((x) - (y)),	\
+		__cmp(op, x, y),				\
+		__cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
 
 #define __clamp(val, lo, hi)	\
 	((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val)))
@@ -44,17 +46,15 @@
 		typeof(val) unique_val = (val);				\
 		typeof(lo) unique_lo = (lo);				\
 		typeof(hi) unique_hi = (hi);				\
+		static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), 	\
+				(lo) <= (hi), true),					\
+			"clamp() low limit " #lo " greater than high limit " #hi);	\
+		static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error");	\
+		static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error");	\
 		__clamp(unique_val, unique_lo, unique_hi); })
 
-#define __clamp_input_check(lo, hi)					\
-        (BUILD_BUG_ON_ZERO(__builtin_choose_expr(			\
-                __is_constexpr((lo) > (hi)), (lo) > (hi), false)))
-
 #define __careful_clamp(val, lo, hi) ({					\
-	__clamp_input_check(lo, hi) +					\
-	__builtin_choose_expr(__typecheck(val, lo) && __typecheck(val, hi) && \
-			      __typecheck(hi, lo) && __is_constexpr(val) && \
-			      __is_constexpr(lo) && __is_constexpr(hi),	\
+	__builtin_choose_expr(__is_constexpr((val) - (lo) + (hi)),	\
 		__clamp(val, lo, hi),					\
 		__clamp_once(val, lo, hi, __UNIQUE_ID(__val),		\
 			     __UNIQUE_ID(__lo), __UNIQUE_ID(__hi))); })
@@ -64,14 +64,14 @@
  * @x: first value
  * @y: second value
  */
-#define min(x, y)	__careful_cmp(x, y, <)
+#define min(x, y)	__careful_cmp(min, x, y)
 
 /**
  * max - return maximum of two values of the same or compatible types
  * @x: first value
  * @y: second value
  */
-#define max(x, y)	__careful_cmp(x, y, >)
+#define max(x, y)	__careful_cmp(max, x, y)
 
 /**
  * min_unsigned - return minimum of two non-negative values
@@ -79,16 +79,16 @@
  * @x: first value
  * @y: second value
  */
-#define min_unsigned(x, y)	\
-	__careful_cmp((x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull, <)
+#define min_unsigned(x, y) \
+	__careful_cmp(min, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull)
 
 /**
  * max_unsigned - return maximum of two non-negative values
  * @x: first value
  * @y: second value
  */
-#define max_unsigned(x, y)	\
-	__careful_cmp((x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull, >)
+#define max_unsigned(x, y) \
+	__careful_cmp(max, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull)
 
 /**
  * min3 - return minimum of three values
@@ -140,7 +140,7 @@
  * @x: first value
  * @y: second value
  */
-#define min_t(type, x, y)	__careful_cmp((type)(x), (type)(y), <)
+#define min_t(type, x, y)	__careful_cmp(min, (type)(x), (type)(y))
 
 /**
  * max_t - return maximum of two values, using the specified type
@@ -148,7 +148,7 @@
  * @x: first value
  * @y: second value
  */
-#define max_t(type, x, y)	__careful_cmp((type)(x), (type)(y), >)
+#define max_t(type, x, y)	__careful_cmp(max, (type)(x), (type)(y))
 
 /**
  * clamp_t - return a value clamped to a given range using a given type
-- 
2.17.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* [PATCH next v2 3/5] minmax: Fix indentation of __cmp_once() and __clamp_once()
  2023-07-28 14:49 [PATCH next v2 0/5] minmax: Relax type checks in min() and max() David Laight
  2023-07-28 14:50 ` [PATCH next v2 1/5] minmax: Add min_unsigned(a, b) and max_unsigned(a, b) David Laight
  2023-07-28 14:51 ` [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness David Laight
@ 2023-07-28 14:52 ` David Laight
  2023-07-28 14:52 ` [PATCH next v2 4/5] minmax: Allow comparisons of 'int' against 'unsigned char/short' David Laight
  2023-07-28 14:53 ` [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants David Laight
  4 siblings, 0 replies; 16+ messages in thread
From: David Laight @ 2023-07-28 14:52 UTC (permalink / raw)
  To: 'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld'

Remove the extra indentation and align continuation markers.

Signed-off-by: David Laight <david.laight@aculab.com>
---
v2: No change
 include/linux/minmax.h | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index cb126853f2be..4c77ac9ed284 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -28,11 +28,11 @@
 #define __cmp(op, x, y)	((x) __cmp_op_##op (y) ? (x) : (y))
 
 #define __cmp_once(op, x, y, unique_x, unique_y) ({	\
-		typeof(x) unique_x = (x);		\
-		typeof(y) unique_y = (y);		\
-		static_assert(__types_ok(x, y),		\
-			#op "(" #x ", " #y ") signedness error, fix types or consider " #op "_unsigned() before " #op "_t()"); \
-		__cmp(op, unique_x, unique_y); })
+	typeof(x) unique_x = (x);			\
+	typeof(y) unique_y = (y);			\
+	static_assert(__types_ok(x, y),			\
+		#op "(" #x ", " #y ") signedness error, fix types or consider " #op "_unsigned() before " #op "_t()"); \
+	__cmp(op, unique_x, unique_y); })
 
 #define __careful_cmp(op, x, y)					\
 	__builtin_choose_expr(__is_constexpr((x) - (y)),	\
@@ -42,16 +42,16 @@
 #define __clamp(val, lo, hi)	\
 	((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val)))
 
-#define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({	\
-		typeof(val) unique_val = (val);				\
-		typeof(lo) unique_lo = (lo);				\
-		typeof(hi) unique_hi = (hi);				\
-		static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), 	\
-				(lo) <= (hi), true),					\
-			"clamp() low limit " #lo " greater than high limit " #hi);	\
-		static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error");	\
-		static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error");	\
-		__clamp(unique_val, unique_lo, unique_hi); })
+#define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({		\
+	typeof(val) unique_val = (val);						\
+	typeof(lo) unique_lo = (lo);						\
+	typeof(hi) unique_hi = (hi);						\
+	static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), 	\
+			(lo) <= (hi), true),					\
+		"clamp() low limit " #lo " greater than high limit " #hi);	\
+	static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error");	\
+	static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error");	\
+	__clamp(unique_val, unique_lo, unique_hi); })
 
 #define __careful_clamp(val, lo, hi) ({					\
 	__builtin_choose_expr(__is_constexpr((val) - (lo) + (hi)),	\
-- 
2.17.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* [PATCH next v2 4/5] minmax: Allow comparisons of 'int' against 'unsigned char/short'.
  2023-07-28 14:49 [PATCH next v2 0/5] minmax: Relax type checks in min() and max() David Laight
                   ` (2 preceding siblings ...)
  2023-07-28 14:52 ` [PATCH next v2 3/5] minmax: Fix indentation of __cmp_once() and __clamp_once() David Laight
@ 2023-07-28 14:52 ` David Laight
  2023-07-28 14:53 ` [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants David Laight
  4 siblings, 0 replies; 16+ messages in thread
From: David Laight @ 2023-07-28 14:52 UTC (permalink / raw)
  To: 'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld'

Since 'unsigned char/short' get promoted to 'signed int' it is
safe to compare them against an 'int' value.

Signed-off-by: David Laight <david.laight@aculab.com>
---
v2: No change
 include/linux/minmax.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 4c77ac9ed284..7d3ad9cbbff6 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -20,7 +20,8 @@
 	(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
 
 #define __types_ok(x, y) \
-	(is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
+	(is_signed_type(typeof(x)) == is_signed_type(typeof(y)) ||	\
+		is_signed_type(typeof((x) + 0)) == is_signed_type(typeof((y) + 0)))
 
 #define __cmp_op_min <
 #define __cmp_op_max >
-- 
2.17.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants.
  2023-07-28 14:49 [PATCH next v2 0/5] minmax: Relax type checks in min() and max() David Laight
                   ` (3 preceding siblings ...)
  2023-07-28 14:52 ` [PATCH next v2 4/5] minmax: Allow comparisons of 'int' against 'unsigned char/short' David Laight
@ 2023-07-28 14:53 ` David Laight
  2023-07-28 21:43   ` kernel test robot
  2023-07-31 13:26   ` David Laight
  4 siblings, 2 replies; 16+ messages in thread
From: David Laight @ 2023-07-28 14:53 UTC (permalink / raw)
  To: 'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld'

Convert constants between 0 and INT_MAX to 'int' prior to comparisons
so that min(signed_var, 20u) and, more commonly, min(signed_var, sizeof())
are both valid.

Signed-off-by: David Laight <david.laight@aculab.com>
---
v2: Add cast to fix min/max with pointer types.

 include/linux/minmax.h | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index 7d3ad9cbbff6..28edafb3dcca 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -8,20 +8,30 @@
 /*
  * min()/max()/clamp() macros must accomplish three things:
  *
- * - avoid multiple evaluations of the arguments (so side-effects like
+ * - Avoid multiple evaluations of the arguments (so side-effects like
  *   "x++" happen only once) when non-constant.
- * - perform signed v unsigned type-checking (to generate compile
+ * - Perform signed v unsigned type-checking (to generate compile
  *   errors instead of nasty runtime surprises).
- * - retain result as a constant expressions when called with only
+ *   Constants from 0 to INT_MAX are cast to (int) so can be used
+ *   in comparisons with signed types.
+ * - Retain result as a constant expressions when called with only
  *   constant expressions (to avoid tripping VLA warnings in stack
  *   allocation usage).
  */
 #define __typecheck(x, y) \
 	(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
 
-#define __types_ok(x, y) \
-	(is_signed_type(typeof(x)) == is_signed_type(typeof(y)) ||	\
-		is_signed_type(typeof((x) + 0)) == is_signed_type(typeof((y) + 0)))
+#define __is_noneg_int(x)					\
+	__builtin_choose_expr(!__is_constexpr(x), false, 	\
+		((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
+
+#define __int_const(x)	__builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
+
+#define __is_signed(x)	is_signed_type(typeof(x))
+#define __types_ok(x, y) 					\
+	(__is_signed(x) == __is_signed(y) ||			\
+		__is_signed((x) + 0) == __is_signed((y) + 0) ||	\
+		__is_noneg_int(x) || __is_noneg_int(y))
 
 #define __cmp_op_min <
 #define __cmp_op_max >
@@ -29,24 +39,24 @@
 #define __cmp(op, x, y)	((x) __cmp_op_##op (y) ? (x) : (y))
 
 #define __cmp_once(op, x, y, unique_x, unique_y) ({	\
-	typeof(x) unique_x = (x);			\
-	typeof(y) unique_y = (y);			\
+	typeof(__int_const(x)) unique_x = (x);		\
+	typeof(__int_const(y)) unique_y = (y);		\
 	static_assert(__types_ok(x, y),			\
 		#op "(" #x ", " #y ") signedness error, fix types or consider " #op "_unsigned() before " #op "_t()"); \
 	__cmp(op, unique_x, unique_y); })
 
 #define __careful_cmp(op, x, y)					\
 	__builtin_choose_expr(__is_constexpr((x) - (y)),	\
-		__cmp(op, x, y),				\
+		__cmp(op, __int_const(x), __int_const(y)),	\
 		__cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
 
 #define __clamp(val, lo, hi)	\
 	((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val)))
 
 #define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({		\
-	typeof(val) unique_val = (val);						\
-	typeof(lo) unique_lo = (lo);						\
-	typeof(hi) unique_hi = (hi);						\
+	typeof(__int_const(val)) unique_val = (val);				\
+	typeof(__int_const(lo)) unique_lo = (lo);				\
+	typeof(__int_const(hi)) unique_hi = (hi);				\
 	static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), 	\
 			(lo) <= (hi), true),					\
 		"clamp() low limit " #lo " greater than high limit " #hi);	\
-- 
2.17.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* Re: [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants.
  2023-07-28 14:53 ` [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants David Laight
@ 2023-07-28 21:43   ` kernel test robot
  2023-07-30 16:55     ` David Laight
  2023-07-31 13:26   ` David Laight
  1 sibling, 1 reply; 16+ messages in thread
From: kernel test robot @ 2023-07-28 21:43 UTC (permalink / raw)
  To: David Laight, 'linux-kernel@vger.kernel.org',
	'Andy Shevchenko', 'Andrew Morton',
	'Matthew Wilcox (Oracle)', 'Christoph Hellwig',
	'Jason A. Donenfeld'
  Cc: oe-kbuild-all, Linux Memory Management List

Hi David,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master crng-random/master v6.5-rc3 next-20230728]
[cannot apply to next-20230728]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Laight/minmax-Add-min_unsigned-a-b-and-max_unsigned-a-b/20230728-225439
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/b4ce9dad748e489f9314a2dc95615033%40AcuMS.aculab.com
patch subject: [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants.
config: alpha-randconfig-r024-20230727 (https://download.01.org/0day-ci/archive/20230729/202307290538.EtRKfGgC-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290538.EtRKfGgC-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307290538.EtRKfGgC-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/kernel.h:27,
                    from include/linux/cpumask.h:10,
                    from include/linux/mm_types_task.h:14,
                    from include/linux/mm_types.h:5,
                    from include/linux/buildid.h:5,
                    from include/linux/module.h:14,
                    from net/ceph/osdmap.c:5:
   net/ceph/osdmap.c: In function 'osdmap_decode':
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:27: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                           ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:27: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min'
    1773 |         err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end)));
         |                                                      ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:45: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                                             ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:43: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min'
    1773 |         err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end)));
         |                                                      ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:51: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                                                   ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:27: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min'
    1773 |         err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end)));
         |                                                      ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:57: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                                                         ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:43: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min'
    1773 |         err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end)));
         |                                                      ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:42:16: note: in expansion of macro '__int_const'
      42 |         typeof(__int_const(x)) unique_x = (x);          \
         |                ^~~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min'
    1773 |         err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end)));
         |                                                      ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:43:16: note: in expansion of macro '__int_const'
      43 |         typeof(__int_const(y)) unique_y = (y);          \
         |                ^~~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min'
    1773 |         err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end)));
         |                                                      ^~~
   In file included from include/linux/container_of.h:5,
                    from include/linux/list.h:5,
                    from include/linux/module.h:12:
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   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:44:9: note: in expansion of macro 'static_assert'
      44 |         static_assert(__types_ok(x, y),                 \
         |         ^~~~~~~~~~~~~
   include/linux/minmax.h:34:17: note: in expansion of macro '__is_noneg_int'
      34 |                 __is_noneg_int(x) || __is_noneg_int(y))
         |                 ^~~~~~~~~~~~~~
   include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok'
      44 |         static_assert(__types_ok(x, y),                 \
         |                       ^~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min'
    1773 |         err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end)));
         |                                                      ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   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:44:9: note: in expansion of macro 'static_assert'
      44 |         static_assert(__types_ok(x, y),                 \
         |         ^~~~~~~~~~~~~
   include/linux/minmax.h:34:38: note: in expansion of macro '__is_noneg_int'
      34 |                 __is_noneg_int(x) || __is_noneg_int(y))
         |                                      ^~~~~~~~~~~~~~
   include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok'
      44 |         static_assert(__types_ok(x, y),                 \
         |                       ^~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min'
    1773 |         err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end)));
         |                                                      ^~~
   net/ceph/osdmap.c: In function 'osdmap_apply_incremental':
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:27: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                           ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:27: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min'
    2000 |                 return ceph_osdmap_decode(p, min(*p+len, end), msgr2);
         |                                              ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:45: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                                             ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:43: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min'
    2000 |                 return ceph_osdmap_decode(p, min(*p+len, end), msgr2);
         |                                              ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:51: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                                                   ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:27: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min'
    2000 |                 return ceph_osdmap_decode(p, min(*p+len, end), msgr2);
         |                                              ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:57: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                                                         ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:43: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min'
    2000 |                 return ceph_osdmap_decode(p, min(*p+len, end), msgr2);
         |                                              ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:42:16: note: in expansion of macro '__int_const'
      42 |         typeof(__int_const(x)) unique_x = (x);          \
         |                ^~~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min'
    2000 |                 return ceph_osdmap_decode(p, min(*p+len, end), msgr2);
         |                                              ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:43:16: note: in expansion of macro '__int_const'
      43 |         typeof(__int_const(y)) unique_y = (y);          \
         |                ^~~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min'
    2000 |                 return ceph_osdmap_decode(p, min(*p+len, end), msgr2);
         |                                              ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   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:44:9: note: in expansion of macro 'static_assert'
      44 |         static_assert(__types_ok(x, y),                 \
         |         ^~~~~~~~~~~~~
   include/linux/minmax.h:34:17: note: in expansion of macro '__is_noneg_int'
      34 |                 __is_noneg_int(x) || __is_noneg_int(y))
         |                 ^~~~~~~~~~~~~~
   include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok'
      44 |         static_assert(__types_ok(x, y),                 \
         |                       ^~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min'
    2000 |                 return ceph_osdmap_decode(p, min(*p+len, end), msgr2);
         |                                              ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   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:44:9: note: in expansion of macro 'static_assert'
      44 |         static_assert(__types_ok(x, y),                 \
         |         ^~~~~~~~~~~~~
   include/linux/minmax.h:34:38: note: in expansion of macro '__is_noneg_int'
      34 |                 __is_noneg_int(x) || __is_noneg_int(y))
         |                                      ^~~~~~~~~~~~~~
   include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok'
      44 |         static_assert(__types_ok(x, y),                 \
         |                       ^~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min'
    2000 |                 return ceph_osdmap_decode(p, min(*p+len, end), msgr2);
         |                                              ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:27: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                           ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:27: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min'
    2007 |                                        crush_decode(*p, min(*p + len, end)));
         |                                                         ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:45: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                                             ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:43: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min'
    2007 |                                        crush_decode(*p, min(*p + len, end)));
         |                                                         ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:51: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                                                   ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:27: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min'
    2007 |                                        crush_decode(*p, min(*p + len, end)));
         |                                                         ^~~
>> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:39:57: note: in definition of macro '__cmp'
      39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y))
         |                                                         ^
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:50:43: note: in expansion of macro '__int_const'
      50 |                 __cmp(op, __int_const(x), __int_const(y)),      \
         |                                           ^~~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min'
    2007 |                                        crush_decode(*p, min(*p + len, end)));
         |                                                         ^~~
   include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:42:16: note: in expansion of macro '__int_const'
      42 |         typeof(__int_const(x)) unique_x = (x);          \
         |                ^~~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min'
    2007 |                                        crush_decode(*p, min(*p + len, end)));
         |                                                         ^~~
   include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int'
      28 | #define __int_const(x)  __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x))
         |                                               ^~~~~~~~~~~~~~
   include/linux/minmax.h:43:16: note: in expansion of macro '__int_const'
      43 |         typeof(__int_const(y)) unique_y = (y);          \
         |                ^~~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min'
    2007 |                                        crush_decode(*p, min(*p + len, end)));
         |                                                         ^~~
   include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   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:44:9: note: in expansion of macro 'static_assert'
      44 |         static_assert(__types_ok(x, y),                 \
         |         ^~~~~~~~~~~~~
   include/linux/minmax.h:34:17: note: in expansion of macro '__is_noneg_int'
      34 |                 __is_noneg_int(x) || __is_noneg_int(y))
         |                 ^~~~~~~~~~~~~~
   include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok'
      44 |         static_assert(__types_ok(x, y),                 \
         |                       ^~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min'
    2007 |                                        crush_decode(*p, min(*p + len, end)));
         |                                                         ^~~
   include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
      26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
         |                      ^~
   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:44:9: note: in expansion of macro 'static_assert'
      44 |         static_assert(__types_ok(x, y),                 \
         |         ^~~~~~~~~~~~~
   include/linux/minmax.h:34:38: note: in expansion of macro '__is_noneg_int'
      34 |                 __is_noneg_int(x) || __is_noneg_int(y))
         |                                      ^~~~~~~~~~~~~~
   include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok'
      44 |         static_assert(__types_ok(x, y),                 \
         |                       ^~~~~~~~~~
   include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once'
      51 |                 __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
         |                 ^~~~~~~~~~
   include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp'
      78 | #define min(x, y)       __careful_cmp(min, x, y)
         |                         ^~~~~~~~~~~~~
   net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min'
    2007 |                                        crush_decode(*p, min(*p + len, end)));
..


vim +26 include/linux/minmax.h

     7	
     8	/*
     9	 * min()/max()/clamp() macros must accomplish three things:
    10	 *
    11	 * - Avoid multiple evaluations of the arguments (so side-effects like
    12	 *   "x++" happen only once) when non-constant.
    13	 * - Perform signed v unsigned type-checking (to generate compile
    14	 *   errors instead of nasty runtime surprises).
    15	 *   Constants from 0 to INT_MAX are cast to (int) so can be used
    16	 *   in comparisons with signed types.
    17	 * - Retain result as a constant expressions when called with only
    18	 *   constant expressions (to avoid tripping VLA warnings in stack
    19	 *   allocation usage).
    20	 */
    21	#define __typecheck(x, y) \
    22		(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
    23	
    24	#define __is_noneg_int(x)					\
    25		__builtin_choose_expr(!__is_constexpr(x), false, 	\
  > 26			((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
    27	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.
  2023-07-28 14:51 ` [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness David Laight
@ 2023-07-29  2:00   ` kernel test robot
  2023-07-30 14:55     ` David Laight
  2023-07-31 21:43   ` kernel test robot
  1 sibling, 1 reply; 16+ messages in thread
From: kernel test robot @ 2023-07-29  2:00 UTC (permalink / raw)
  To: David Laight, 'linux-kernel@vger.kernel.org',
	'Andy Shevchenko', 'Andrew Morton',
	'Matthew Wilcox (Oracle)', 'Christoph Hellwig',
	'Jason A. Donenfeld'
  Cc: llvm, oe-kbuild-all, Linux Memory Management List

Hi David,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master crng-random/master v6.5-rc3 next-20230728]
[cannot apply to next-20230728]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Laight/minmax-Add-min_unsigned-a-b-and-max_unsigned-a-b/20230728-225439
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/bf92800b0c5445e2b2ca8c88e1f5e90f%40AcuMS.aculab.com
patch subject: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.
config: s390-randconfig-r044-20230728 (https://download.01.org/0day-ci/archive/20230729/202307290943.ODVeyeK6-lkp@intel.com/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290943.ODVeyeK6-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202307290943.ODVeyeK6-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from mm/percpu.c:73:
   In file included from include/linux/memblock.h:13:
   In file included from arch/s390/include/asm/dma.h:5:
   In file included from include/linux/io.h:13:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __raw_readb(PCI_IOBASE + addr);
                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
   #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
                                                             ^
   include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
   #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
                                                        ^
   In file included from mm/percpu.c:73:
   In file included from include/linux/memblock.h:13:
   In file included from arch/s390/include/asm/dma.h:5:
   In file included from include/linux/io.h:13:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
                                                             ^
   include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
   #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
                                                        ^
   In file included from mm/percpu.c:73:
   In file included from include/linux/memblock.h:13:
   In file included from arch/s390/include/asm/dma.h:5:
   In file included from include/linux/io.h:13:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsb(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsw(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsl(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesb(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesw(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesl(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
>> mm/percpu.c:3102:10: error: static assertion expression is not an integral constant expression
                   base = min(ptr, base);
                          ^~~~~~~~~~~~~~
   include/linux/minmax.h:67:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(min, x, y)
                           ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
                   static_assert(__types_ok(x, y),         \
                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:23:2: note: expanded from macro '__types_ok'
           (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
           ^
   include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
   #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
                                    ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
   #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
                                                          ^~~~
   mm/percpu.c:3102:10: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
   include/linux/minmax.h:67:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(min, x, y)
                           ^
   include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
                   ^
   include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
                   static_assert(__types_ok(x, y),         \
                                 ^
   include/linux/minmax.h:23:3: note: expanded from macro '__types_ok'
           (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
            ^
   include/linux/compiler.h:237:32: note: expanded from macro 'is_signed_type'
   #define is_signed_type(type) (((type)(-1)) < (__force type)1)
                                  ^
   12 warnings and 1 error generated.
--
   In file included from mm/kmemleak.c:86:
   In file included from include/linux/memblock.h:13:
   In file included from arch/s390/include/asm/dma.h:5:
   In file included from include/linux/io.h:13:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __raw_readb(PCI_IOBASE + addr);
                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
   #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
                                                             ^
   include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
   #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
                                                        ^
   In file included from mm/kmemleak.c:86:
   In file included from include/linux/memblock.h:13:
   In file included from arch/s390/include/asm/dma.h:5:
   In file included from include/linux/io.h:13:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
                                                             ^
   include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
   #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
                                                        ^
   In file included from mm/kmemleak.c:86:
   In file included from include/linux/memblock.h:13:
   In file included from arch/s390/include/asm/dma.h:5:
   In file included from include/linux/io.h:13:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsb(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsw(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsl(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesb(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesw(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesl(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
>> mm/kmemleak.c:1389:10: error: static assertion expression is not an integral constant expression
                   next = min(start + MAX_SCAN_SIZE, end);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:67:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(min, x, y)
                           ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
                   static_assert(__types_ok(x, y),         \
                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:23:2: note: expanded from macro '__types_ok'
           (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
           ^
   include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
   #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
                                    ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
   #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
                                                          ^~~~
   mm/kmemleak.c:1389:10: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
   include/linux/minmax.h:67:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(min, x, y)
                           ^
   include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
                   ^
   include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
                   static_assert(__types_ok(x, y),         \
                                 ^
   include/linux/minmax.h:23:3: note: expanded from macro '__types_ok'
           (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
            ^
   include/linux/compiler.h:237:32: note: expanded from macro 'is_signed_type'
   #define is_signed_type(type) (((type)(-1)) < (__force type)1)
                                  ^
   mm/kmemleak.c:1429:11: error: static assertion expression is not an integral constant expression
                           next = min(start + MAX_SCAN_SIZE, end);
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:67:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(min, x, y)
                           ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
                   static_assert(__types_ok(x, y),         \
                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:23:2: note: expanded from macro '__types_ok'
           (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
           ^
   include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
   #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
                                    ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
   #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
                                                          ^~~~
   mm/kmemleak.c:1429:11: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
   include/linux/minmax.h:67:19: note: expanded from macro 'min'
   #define min(x, y)       __careful_cmp(min, x, y)
                           ^
   include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
                   ^
   include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
                   static_assert(__types_ok(x, y),         \
                                 ^
   include/linux/minmax.h:23:3: note: expanded from macro '__types_ok'
           (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
            ^
   include/linux/compiler.h:237:32: note: expanded from macro 'is_signed_type'
   #define is_signed_type(type) (((type)(-1)) < (__force type)1)
                                  ^
   12 warnings and 2 errors generated.
--
   In file included from crypto/skcipher.c:15:
   In file included from include/crypto/scatterwalk.h:18:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __raw_readb(PCI_IOBASE + addr);
                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
   #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
                                                             ^
   include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
   #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
                                                        ^
   In file included from crypto/skcipher.c:15:
   In file included from include/crypto/scatterwalk.h:18:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
                                                             ^
   include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
   #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
                                                        ^
   In file included from crypto/skcipher.c:15:
   In file included from include/crypto/scatterwalk.h:18:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/s390/include/asm/io.h:78:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsb(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsw(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsl(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesb(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesw(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesl(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
>> crypto/skcipher.c:80:9: error: static assertion expression is not an integral constant expression
           return max(start, end_page);
                  ^~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:74:19: note: expanded from macro 'max'
   #define max(x, y)       __careful_cmp(max, x, y)
                           ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
                   static_assert(__types_ok(x, y),         \
                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:23:2: note: expanded from macro '__types_ok'
           (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
           ^
   include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
   #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
                                    ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
   #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
                                                          ^~~~
   crypto/skcipher.c:80:9: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
   include/linux/minmax.h:74:19: note: expanded from macro 'max'
   #define max(x, y)       __careful_cmp(max, x, y)
                           ^
   include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
                   ^
   include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
                   static_assert(__types_ok(x, y),         \
                                 ^
   include/linux/minmax.h:23:3: note: expanded from macro '__types_ok'
           (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
            ^
   include/linux/compiler.h:237:32: note: expanded from macro 'is_signed_type'
   #define is_signed_type(type) (((type)(-1)) < (__force type)1)
                                  ^
   12 warnings and 1 error generated.
..


vim +3102 mm/percpu.c

3c9a024fde58b08 Tejun Heo       2010-09-09  3022  
3c9a024fde58b08 Tejun Heo       2010-09-09  3023  #if defined(BUILD_EMBED_FIRST_CHUNK)
66c3a75772247c3 Tejun Heo       2009-03-10  3024  /**
66c3a75772247c3 Tejun Heo       2009-03-10  3025   * pcpu_embed_first_chunk - embed the first percpu chunk into bootmem
66c3a75772247c3 Tejun Heo       2009-03-10  3026   * @reserved_size: the size of reserved percpu area in bytes
4ba6ce250e406b2 Tejun Heo       2010-06-27  3027   * @dyn_size: minimum free size for dynamic allocation in bytes
c8826dd538602d7 Tejun Heo       2009-08-14  3028   * @atom_size: allocation atom size
c8826dd538602d7 Tejun Heo       2009-08-14  3029   * @cpu_distance_fn: callback to determine distance between cpus, optional
1ca3fb3abd2b615 Kefeng Wang     2022-01-19  3030   * @cpu_to_nd_fn: callback to convert cpu to it's node, optional
66c3a75772247c3 Tejun Heo       2009-03-10  3031   *
66c3a75772247c3 Tejun Heo       2009-03-10  3032   * This is a helper to ease setting up embedded first percpu chunk and
66c3a75772247c3 Tejun Heo       2009-03-10  3033   * can be called where pcpu_setup_first_chunk() is expected.
66c3a75772247c3 Tejun Heo       2009-03-10  3034   *
66c3a75772247c3 Tejun Heo       2009-03-10  3035   * If this function is used to setup the first chunk, it is allocated
23f917169ef157a Kefeng Wang     2022-01-19  3036   * by calling pcpu_fc_alloc and used as-is without being mapped into
c8826dd538602d7 Tejun Heo       2009-08-14  3037   * vmalloc area.  Allocations are always whole multiples of @atom_size
c8826dd538602d7 Tejun Heo       2009-08-14  3038   * aligned to @atom_size.
c8826dd538602d7 Tejun Heo       2009-08-14  3039   *
c8826dd538602d7 Tejun Heo       2009-08-14  3040   * This enables the first chunk to piggy back on the linear physical
c8826dd538602d7 Tejun Heo       2009-08-14  3041   * mapping which often uses larger page size.  Please note that this
c8826dd538602d7 Tejun Heo       2009-08-14  3042   * can result in very sparse cpu->unit mapping on NUMA machines thus
c8826dd538602d7 Tejun Heo       2009-08-14  3043   * requiring large vmalloc address space.  Don't use this allocator if
c8826dd538602d7 Tejun Heo       2009-08-14  3044   * vmalloc space is not orders of magnitude larger than distances
c8826dd538602d7 Tejun Heo       2009-08-14  3045   * between node memory addresses (ie. 32bit NUMA machines).
66c3a75772247c3 Tejun Heo       2009-03-10  3046   *
4ba6ce250e406b2 Tejun Heo       2010-06-27  3047   * @dyn_size specifies the minimum dynamic area size.
66c3a75772247c3 Tejun Heo       2009-03-10  3048   *
66c3a75772247c3 Tejun Heo       2009-03-10  3049   * If the needed size is smaller than the minimum or specified unit
23f917169ef157a Kefeng Wang     2022-01-19  3050   * size, the leftover is returned using pcpu_fc_free.
66c3a75772247c3 Tejun Heo       2009-03-10  3051   *
66c3a75772247c3 Tejun Heo       2009-03-10  3052   * RETURNS:
fb435d5233f8b6f Tejun Heo       2009-08-14  3053   * 0 on success, -errno on failure.
66c3a75772247c3 Tejun Heo       2009-03-10  3054   */
4ba6ce250e406b2 Tejun Heo       2010-06-27  3055  int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size,
c8826dd538602d7 Tejun Heo       2009-08-14  3056  				  size_t atom_size,
c8826dd538602d7 Tejun Heo       2009-08-14  3057  				  pcpu_fc_cpu_distance_fn_t cpu_distance_fn,
23f917169ef157a Kefeng Wang     2022-01-19  3058  				  pcpu_fc_cpu_to_node_fn_t cpu_to_nd_fn)
66c3a75772247c3 Tejun Heo       2009-03-10  3059  {
c8826dd538602d7 Tejun Heo       2009-08-14  3060  	void *base = (void *)ULONG_MAX;
c8826dd538602d7 Tejun Heo       2009-08-14  3061  	void **areas = NULL;
fd1e8a1fe2b54df Tejun Heo       2009-08-14  3062  	struct pcpu_alloc_info *ai;
93c76b6b2faaad7 zijun_hu        2016-10-05  3063  	size_t size_sum, areas_size;
93c76b6b2faaad7 zijun_hu        2016-10-05  3064  	unsigned long max_distance;
163fa23435cc9c7 Kefeng Wang     2019-07-03  3065  	int group, i, highest_group, rc = 0;
66c3a75772247c3 Tejun Heo       2009-03-10  3066  
c8826dd538602d7 Tejun Heo       2009-08-14  3067  	ai = pcpu_build_alloc_info(reserved_size, dyn_size, atom_size,
c8826dd538602d7 Tejun Heo       2009-08-14  3068  				   cpu_distance_fn);
fd1e8a1fe2b54df Tejun Heo       2009-08-14  3069  	if (IS_ERR(ai))
fd1e8a1fe2b54df Tejun Heo       2009-08-14  3070  		return PTR_ERR(ai);
66c3a75772247c3 Tejun Heo       2009-03-10  3071  
fd1e8a1fe2b54df Tejun Heo       2009-08-14  3072  	size_sum = ai->static_size + ai->reserved_size + ai->dyn_size;
c8826dd538602d7 Tejun Heo       2009-08-14  3073  	areas_size = PFN_ALIGN(ai->nr_groups * sizeof(void *));
fa8a7094ba1679b Tejun Heo       2009-06-22  3074  
26fb3dae0a1ec78 Mike Rapoport   2019-03-11  3075  	areas = memblock_alloc(areas_size, SMP_CACHE_BYTES);
c8826dd538602d7 Tejun Heo       2009-08-14  3076  	if (!areas) {
fb435d5233f8b6f Tejun Heo       2009-08-14  3077  		rc = -ENOMEM;
c8826dd538602d7 Tejun Heo       2009-08-14  3078  		goto out_free;
fa8a7094ba1679b Tejun Heo       2009-06-22  3079  	}
66c3a75772247c3 Tejun Heo       2009-03-10  3080  
9b7396624a7b503 zijun_hu        2016-10-05  3081  	/* allocate, copy and determine base address & max_distance */
9b7396624a7b503 zijun_hu        2016-10-05  3082  	highest_group = 0;
c8826dd538602d7 Tejun Heo       2009-08-14  3083  	for (group = 0; group < ai->nr_groups; group++) {
c8826dd538602d7 Tejun Heo       2009-08-14  3084  		struct pcpu_group_info *gi = &ai->groups[group];
c8826dd538602d7 Tejun Heo       2009-08-14  3085  		unsigned int cpu = NR_CPUS;
c8826dd538602d7 Tejun Heo       2009-08-14  3086  		void *ptr;
c8826dd538602d7 Tejun Heo       2009-08-14  3087  
c8826dd538602d7 Tejun Heo       2009-08-14  3088  		for (i = 0; i < gi->nr_units && cpu == NR_CPUS; i++)
c8826dd538602d7 Tejun Heo       2009-08-14  3089  			cpu = gi->cpu_map[i];
c8826dd538602d7 Tejun Heo       2009-08-14  3090  		BUG_ON(cpu == NR_CPUS);
c8826dd538602d7 Tejun Heo       2009-08-14  3091  
c8826dd538602d7 Tejun Heo       2009-08-14  3092  		/* allocate space for the whole group */
23f917169ef157a Kefeng Wang     2022-01-19  3093  		ptr = pcpu_fc_alloc(cpu, gi->nr_units * ai->unit_size, atom_size, cpu_to_nd_fn);
c8826dd538602d7 Tejun Heo       2009-08-14  3094  		if (!ptr) {
c8826dd538602d7 Tejun Heo       2009-08-14  3095  			rc = -ENOMEM;
c8826dd538602d7 Tejun Heo       2009-08-14  3096  			goto out_free_areas;
c8826dd538602d7 Tejun Heo       2009-08-14  3097  		}
f528f0b8e53d73b Catalin Marinas 2011-09-26  3098  		/* kmemleak tracks the percpu allocations separately */
a317ebccaa36099 Patrick Wang    2022-07-05  3099  		kmemleak_ignore_phys(__pa(ptr));
c8826dd538602d7 Tejun Heo       2009-08-14  3100  		areas[group] = ptr;
c8826dd538602d7 Tejun Heo       2009-08-14  3101  
c8826dd538602d7 Tejun Heo       2009-08-14 @3102  		base = min(ptr, base);
9b7396624a7b503 zijun_hu        2016-10-05  3103  		if (ptr > areas[highest_group])
9b7396624a7b503 zijun_hu        2016-10-05  3104  			highest_group = group;
9b7396624a7b503 zijun_hu        2016-10-05  3105  	}
9b7396624a7b503 zijun_hu        2016-10-05  3106  	max_distance = areas[highest_group] - base;
9b7396624a7b503 zijun_hu        2016-10-05  3107  	max_distance += ai->unit_size * ai->groups[highest_group].nr_units;
9b7396624a7b503 zijun_hu        2016-10-05  3108  
9b7396624a7b503 zijun_hu        2016-10-05  3109  	/* warn if maximum distance is further than 75% of vmalloc space */
9b7396624a7b503 zijun_hu        2016-10-05  3110  	if (max_distance > VMALLOC_TOTAL * 3 / 4) {
9b7396624a7b503 zijun_hu        2016-10-05  3111  		pr_warn("max_distance=0x%lx too large for vmalloc space 0x%lx\n",
9b7396624a7b503 zijun_hu        2016-10-05  3112  				max_distance, VMALLOC_TOTAL);
9b7396624a7b503 zijun_hu        2016-10-05  3113  #ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
9b7396624a7b503 zijun_hu        2016-10-05  3114  		/* and fail if we have fallback */
9b7396624a7b503 zijun_hu        2016-10-05  3115  		rc = -EINVAL;
9b7396624a7b503 zijun_hu        2016-10-05  3116  		goto out_free_areas;
9b7396624a7b503 zijun_hu        2016-10-05  3117  #endif
42b64281453249d Tejun Heo       2012-04-27  3118  	}
42b64281453249d Tejun Heo       2012-04-27  3119  
42b64281453249d Tejun Heo       2012-04-27  3120  	/*
42b64281453249d Tejun Heo       2012-04-27  3121  	 * Copy data and free unused parts.  This should happen after all
42b64281453249d Tejun Heo       2012-04-27  3122  	 * allocations are complete; otherwise, we may end up with
42b64281453249d Tejun Heo       2012-04-27  3123  	 * overlapping groups.
42b64281453249d Tejun Heo       2012-04-27  3124  	 */
42b64281453249d Tejun Heo       2012-04-27  3125  	for (group = 0; group < ai->nr_groups; group++) {
42b64281453249d Tejun Heo       2012-04-27  3126  		struct pcpu_group_info *gi = &ai->groups[group];
42b64281453249d Tejun Heo       2012-04-27  3127  		void *ptr = areas[group];
66c3a75772247c3 Tejun Heo       2009-03-10  3128  
c8826dd538602d7 Tejun Heo       2009-08-14  3129  		for (i = 0; i < gi->nr_units; i++, ptr += ai->unit_size) {
c8826dd538602d7 Tejun Heo       2009-08-14  3130  			if (gi->cpu_map[i] == NR_CPUS) {
c8826dd538602d7 Tejun Heo       2009-08-14  3131  				/* unused unit, free whole */
23f917169ef157a Kefeng Wang     2022-01-19  3132  				pcpu_fc_free(ptr, ai->unit_size);
c8826dd538602d7 Tejun Heo       2009-08-14  3133  				continue;
c8826dd538602d7 Tejun Heo       2009-08-14  3134  			}
c8826dd538602d7 Tejun Heo       2009-08-14  3135  			/* copy and return the unused part */
fd1e8a1fe2b54df Tejun Heo       2009-08-14  3136  			memcpy(ptr, __per_cpu_load, ai->static_size);
23f917169ef157a Kefeng Wang     2022-01-19  3137  			pcpu_fc_free(ptr + size_sum, ai->unit_size - size_sum);
c8826dd538602d7 Tejun Heo       2009-08-14  3138  		}
66c3a75772247c3 Tejun Heo       2009-03-10  3139  	}
66c3a75772247c3 Tejun Heo       2009-03-10  3140  
c8826dd538602d7 Tejun Heo       2009-08-14  3141  	/* base address is now known, determine group base offsets */
6ea529a2037ce66 Tejun Heo       2009-09-24  3142  	for (group = 0; group < ai->nr_groups; group++) {
c8826dd538602d7 Tejun Heo       2009-08-14  3143  		ai->groups[group].base_offset = areas[group] - base;
6ea529a2037ce66 Tejun Heo       2009-09-24  3144  	}
c8826dd538602d7 Tejun Heo       2009-08-14  3145  
00206a69ee32f03 Matteo Croce    2019-03-18  3146  	pr_info("Embedded %zu pages/cpu s%zu r%zu d%zu u%zu\n",
00206a69ee32f03 Matteo Croce    2019-03-18  3147  		PFN_DOWN(size_sum), ai->static_size, ai->reserved_size,
fd1e8a1fe2b54df Tejun Heo       2009-08-14  3148  		ai->dyn_size, ai->unit_size);
66c3a75772247c3 Tejun Heo       2009-03-10  3149  
163fa23435cc9c7 Kefeng Wang     2019-07-03  3150  	pcpu_setup_first_chunk(ai, base);
c8826dd538602d7 Tejun Heo       2009-08-14  3151  	goto out_free;
c8826dd538602d7 Tejun Heo       2009-08-14  3152  
c8826dd538602d7 Tejun Heo       2009-08-14  3153  out_free_areas:
c8826dd538602d7 Tejun Heo       2009-08-14  3154  	for (group = 0; group < ai->nr_groups; group++)
f851c8d8583891a Michael Holzheu 2013-09-17  3155  		if (areas[group])
23f917169ef157a Kefeng Wang     2022-01-19  3156  			pcpu_fc_free(areas[group],
c8826dd538602d7 Tejun Heo       2009-08-14  3157  				ai->groups[group].nr_units * ai->unit_size);
c8826dd538602d7 Tejun Heo       2009-08-14  3158  out_free:
fd1e8a1fe2b54df Tejun Heo       2009-08-14  3159  	pcpu_free_alloc_info(ai);
c8826dd538602d7 Tejun Heo       2009-08-14  3160  	if (areas)
4421cca0a3e4833 Mike Rapoport   2021-11-05  3161  		memblock_free(areas, areas_size);
fb435d5233f8b6f Tejun Heo       2009-08-14  3162  	return rc;
fa8a7094ba1679b Tejun Heo       2009-06-22  3163  }
3c9a024fde58b08 Tejun Heo       2010-09-09  3164  #endif /* BUILD_EMBED_FIRST_CHUNK */
d4b95f80399471e Tejun Heo       2009-07-04  3165  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* RE: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.
  2023-07-29  2:00   ` kernel test robot
@ 2023-07-30 14:55     ` David Laight
  2023-07-30 17:05       ` Nathan Chancellor
  0 siblings, 1 reply; 16+ messages in thread
From: David Laight @ 2023-07-30 14:55 UTC (permalink / raw)
  To: 'kernel test robot',
	'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld'
  Cc: llvm, oe-kbuild-all

From: kernel test robot
> Sent: 29 July 2023 03:01
> 
> kernel test robot noticed the following build errors:
> 
...)
> compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git
> 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
> reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290943.ODVeyeK6-
> lkp@intel.com/reproduce)
> 
...
> >> mm/percpu.c:3102:10: error: static assertion expression is not an integral constant expression
>                    base = min(ptr, base);
>                           ^~~~~~~~~~~~~~
...                    ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
>    include/linux/minmax.h:23:2: note: expanded from macro '__types_ok'
>            (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
>            ^
...
>    mm/percpu.c:3102:10: note: cast that performs the conversions of a reinterpret_cast is not allowed
> in a constant expression

That is a C++ error that seems to have crept into C.
The relevant definition is:

#define is_signed_type(type)  (((type)(-1)) < (type)1)

This seems to have been fixed in clang 16.0.0.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* RE: [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants.
  2023-07-28 21:43   ` kernel test robot
@ 2023-07-30 16:55     ` David Laight
  0 siblings, 0 replies; 16+ messages in thread
From: David Laight @ 2023-07-30 16:55 UTC (permalink / raw)
  To: 'kernel test robot',
	'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld'
  Cc: oe-kbuild-all, Linux Memory Management List

From: kernel test robot
> Sent: 28 July 2023 22:43
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on akpm-mm/mm-everything]
> [also build test WARNING on linus/master crng-random/master v6.5-rc3 next-20230728]
> [cannot apply to next-20230728]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/David-Laight/minmax-Add-min_unsigned-a-b-and-
> max_unsigned-a-b/20230728-225439
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
> patch link:    https://lore.kernel.org/r/b4ce9dad748e489f9314a2dc95615033%40AcuMS.aculab.com
> patch subject: [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small
> unsigned constants.
> config: alpha-randconfig-r024-20230727 (https://download.01.org/0day-
> ci/archive/20230729/202307290538.EtRKfGgC-lkp@intel.com/config)
> compiler: alpha-linux-gcc (GCC) 12.3.0
> reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290538.EtRKfGgC-
> lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202307290538.EtRKfGgC-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
>    In file included from include/linux/kernel.h:27,
>                     from include/linux/cpumask.h:10,
>                     from include/linux/mm_types_task.h:14,
>                     from include/linux/mm_types.h:5,
>                     from include/linux/buildid.h:5,
>                     from include/linux/module.h:14,
>                     from net/ceph/osdmap.c:5:
>    net/ceph/osdmap.c: In function 'osdmap_decode':
> >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra]
>       26 |                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))

I have a cunning plan to fix this (and warnings about testing 'unsigned >= 0').
Basically replace the first test with:
	__builtin_choose_expr(is_signed(x), x, 1) >= 0

(Also fixes the build with clang < 16.)

Hopefully that v3 will keep the build robert happy :-)

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* Re: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.
  2023-07-30 14:55     ` David Laight
@ 2023-07-30 17:05       ` Nathan Chancellor
  2023-07-30 17:33         ` David Laight
  0 siblings, 1 reply; 16+ messages in thread
From: Nathan Chancellor @ 2023-07-30 17:05 UTC (permalink / raw)
  To: David Laight
  Cc: 'kernel test robot',
	'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld',
	llvm, oe-kbuild-all

On Sun, Jul 30, 2023 at 02:55:50PM +0000, David Laight wrote:
> From: kernel test robot
> > Sent: 29 July 2023 03:01
> > 
> > kernel test robot noticed the following build errors:
> > 
> ...)
> > compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git
> > 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
> > reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290943.ODVeyeK6-
> > lkp@intel.com/reproduce)
> > 
> ...
> > >> mm/percpu.c:3102:10: error: static assertion expression is not an integral constant expression
> >                    base = min(ptr, base);
> >                           ^~~~~~~~~~~~~~
> ...                    ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
> >    include/linux/minmax.h:23:2: note: expanded from macro '__types_ok'
> >            (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
> >            ^
> ...
> >    mm/percpu.c:3102:10: note: cast that performs the conversions of a reinterpret_cast is not allowed
> > in a constant expression
> 
> That is a C++ error that seems to have crept into C.
> The relevant definition is:
> 
> #define is_signed_type(type)  (((type)(-1)) < (type)1)
> 
> This seems to have been fixed in clang 16.0.0.

Indeed, it looks like

https://github.com/llvm/llvm-project/commit/a181de452df311d7647329120d05f4eb9c158b6c

fixed this as a result of the discussion at

https://github.com/llvm/llvm-project/issues/57687, which certainly makes
sense.

Cheers,
Nathan

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

* RE: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.
  2023-07-30 17:05       ` Nathan Chancellor
@ 2023-07-30 17:33         ` David Laight
  0 siblings, 0 replies; 16+ messages in thread
From: David Laight @ 2023-07-30 17:33 UTC (permalink / raw)
  To: 'Nathan Chancellor'
  Cc: 'kernel test robot',
	'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld',
	llvm, oe-kbuild-all

From: Nathan Chancellor
> Sent: 30 July 2023 18:06
> 
> On Sun, Jul 30, 2023 at 02:55:50PM +0000, David Laight wrote:
> > From: kernel test robot
> > > Sent: 29 July 2023 03:01
> > >
> > > kernel test robot noticed the following build errors:
> > >
> > ...)
> > > compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git
> > > 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
> > > reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290943.ODVeyeK6-
> > > lkp@intel.com/reproduce)
> > >
> > ...
> > > >> mm/percpu.c:3102:10: error: static assertion expression is not an integral constant expression
> > >                    base = min(ptr, base);
> > >                           ^~~~~~~~~~~~~~
> > ...                    ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >    include/linux/minmax.h:23:2: note: expanded from macro '__types_ok'
> > >            (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
> > >            ^
> > ...
> > >    mm/percpu.c:3102:10: note: cast that performs the conversions of a reinterpret_cast is not allowed
> > > in a constant expression
> >
> > That is a C++ error that seems to have crept into C.
> > The relevant definition is:
> >
> > #define is_signed_type(type)  (((type)(-1)) < (type)1)
> >
> > This seems to have been fixed in clang 16.0.0.
> 
> Indeed, it looks like
> 
> https://github.com/llvm/llvm-project/commit/a181de452df311d7647329120d05f4eb9c158b6c
> 
> fixed this as a result of the discussion at
> 
> https://github.com/llvm/llvm-project/issues/57687, which certainly makes
> sense.

Annoyingly it also isn't a 'proper' compile time constant for pointers.
Wrapping as:
	__builtin_choose_expr(__is_constexpr(is_signed(type(x)), is_signed_type(x), 0)
fixes it for old clang and is also needed to fix the >= 0 check in 5/5.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* RE: [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants.
  2023-07-28 14:53 ` [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants David Laight
  2023-07-28 21:43   ` kernel test robot
@ 2023-07-31 13:26   ` David Laight
  2023-08-01 16:02     ` Nick Desaulniers
  1 sibling, 1 reply; 16+ messages in thread
From: David Laight @ 2023-07-31 13:26 UTC (permalink / raw)
  To: 'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld'
  Cc: 'Nathan Chancellor', llvm

By the time I've done:

#define __is_noneg_int(x)					\
	__builtin_choose_expr(!__is_constexpr(x), false, 	\
		((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))

#define __is_signed(x)                                                         \
       __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))),        \
               is_signed_type(typeof(x)), 0)

#define __types_ok(x, y) 					\
	(__is_signed(x) == __is_signed(y) ||			\
		__is_signed((x) + 0) == __is_signed((y) + 0) ||	\
		__is_noneg_int(x) || __is_noneg_int(y))

the error message for

>  	static_assert(__types_ok(x, y),			\
>  		#op "(" #x ", " #y ") signedness error, fix types or consider " #op "_unsigned() before " #op "_t()"); \

generated by clang 8.0.0 and later is similar to (see https://godbolt.org/z/jq613Gnsa):

<source>:49:12: error: static assertion failed due to requirement '__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) || __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) || (__builtin_choose_expr(!(sizeof(int) == sizeof (*(8 ? ((void *)((long)(a) * 0L)) : (int *)8))), 0, __builtin_choose_expr(__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0), a, 0) >= 0 && (a) <= (int)(long)2147483647)) || (__builtin_choose_expr(!(sizeof(int) == sizeof (*(8 ? ((void *)((long)(2147483648U - 0) * 0L)) : (int *)8))), 0, __builtin_choose_expr(__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0), 2147483648U - 0, 0) >= 0 && (2147483648U - 0) <= (unsigned int)(long)2147483647))': min(a, 0x80000000u - 0) signedness error, fix types or consider min_unsigned() before min_t()

Repeating the expression seems somewhat sub-optimal!
Surely it shouldn't be outputting the expansion of the
input when an error message is supplied?

Is there any (sane) way to stop it being that verbose?

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

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

* Re: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.
  2023-07-28 14:51 ` [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness David Laight
  2023-07-29  2:00   ` kernel test robot
@ 2023-07-31 21:43   ` kernel test robot
  2023-08-01  8:45     ` David Laight
  1 sibling, 1 reply; 16+ messages in thread
From: kernel test robot @ 2023-07-31 21:43 UTC (permalink / raw)
  To: David Laight, 'linux-kernel@vger.kernel.org',
	'Andy Shevchenko', 'Andrew Morton',
	'Matthew Wilcox (Oracle)', 'Christoph Hellwig',
	'Jason A. Donenfeld'
  Cc: llvm, oe-kbuild-all, Linux Memory Management List

Hi David,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master crng-random/master v6.5-rc4 next-20230731]
[cannot apply to next-20230728]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Laight/minmax-Add-min_unsigned-a-b-and-max_unsigned-a-b/20230728-225439
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/bf92800b0c5445e2b2ca8c88e1f5e90f%40AcuMS.aculab.com
patch subject: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.
config: powerpc-mpc5200_defconfig (https://download.01.org/0day-ci/archive/20230801/202308010559.SEtfkzQU-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce: (https://download.01.org/0day-ci/archive/20230801/202308010559.SEtfkzQU-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308010559.SEtfkzQU-lkp@intel.com/

All errors (new ones prefixed by >>):

   ^
   arch/powerpc/include/asm/io.h:610:56: note: expanded from macro '__do_insw'
   #define __do_insw(p, b, n)      readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from drivers/gpu/drm/drm_modes.c:35:
   In file included from include/linux/fb.h:6:
   In file included from include/linux/kgdb.h:19:
   In file included from include/linux/kprobes.h:28:
   In file included from include/linux/ftrace.h:10:
   In file included from include/linux/trace_recursion.h:5:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:672:
   arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:669:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:101:1: note: expanded from here
   __do_insl
   ^
   arch/powerpc/include/asm/io.h:611:56: note: expanded from macro '__do_insl'
   #define __do_insl(p, b, n)      readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
                                          ~~~~~~~~~~~~~~~~~~~~~^
   In file included from drivers/gpu/drm/drm_modes.c:35:
   In file included from include/linux/fb.h:6:
   In file included from include/linux/kgdb.h:19:
   In file included from include/linux/kprobes.h:28:
   In file included from include/linux/ftrace.h:10:
   In file included from include/linux/trace_recursion.h:5:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:672:
   arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:669:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:103:1: note: expanded from here
   __do_outsb
   ^
   arch/powerpc/include/asm/io.h:612:58: note: expanded from macro '__do_outsb'
   #define __do_outsb(p, b, n)     writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from drivers/gpu/drm/drm_modes.c:35:
   In file included from include/linux/fb.h:6:
   In file included from include/linux/kgdb.h:19:
   In file included from include/linux/kprobes.h:28:
   In file included from include/linux/ftrace.h:10:
   In file included from include/linux/trace_recursion.h:5:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:672:
   arch/powerpc/include/asm/io-defs.h:51:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:669:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:105:1: note: expanded from here
   __do_outsw
   ^
   arch/powerpc/include/asm/io.h:613:58: note: expanded from macro '__do_outsw'
   #define __do_outsw(p, b, n)     writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
   In file included from drivers/gpu/drm/drm_modes.c:35:
   In file included from include/linux/fb.h:6:
   In file included from include/linux/kgdb.h:19:
   In file included from include/linux/kprobes.h:28:
   In file included from include/linux/ftrace.h:10:
   In file included from include/linux/trace_recursion.h:5:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/powerpc/include/asm/hardirq.h:6:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:672:
   arch/powerpc/include/asm/io-defs.h:53:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/include/asm/io.h:669:3: note: expanded from macro 'DEF_PCI_AC_NORET'
                   __do_##name al;                                 \
                   ^~~~~~~~~~~~~~
   <scratch space>:107:1: note: expanded from here
   __do_outsl
   ^
   arch/powerpc/include/asm/io.h:614:58: note: expanded from macro '__do_outsl'
   #define __do_outsl(p, b, n)     writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
                                           ~~~~~~~~~~~~~~~~~~~~~^
>> drivers/gpu/drm/drm_modes.c:2474:15: error: static_assert expression is not an integral constant expression
                   extra_ptr = max(bpp_end_ptr, refresh_end_ptr);
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:74:19: note: expanded from macro 'max'
   #define max(x, y)       __careful_cmp(max, x, y)
                           ^~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
                   static_assert(__types_ok(x, y),         \
                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/minmax.h:23:2: note: expanded from macro '__types_ok'
           (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
           ^
   include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
   #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
                                    ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
   #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
                                                          ^~~~
   drivers/gpu/drm/drm_modes.c:2474:15: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
   include/linux/minmax.h:74:19: note: expanded from macro 'max'
   #define max(x, y)       __careful_cmp(max, x, y)
                           ^
   include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
                   __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
                   ^
   include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
                   static_assert(__types_ok(x, y),         \
                                 ^
   include/linux/minmax.h:23:3: note: expanded from macro '__types_ok'
           (is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
            ^
   include/linux/compiler.h:237:32: note: expanded from macro 'is_signed_type'
   #define is_signed_type(type) (((type)(-1)) < (__force type)1)
                                  ^
   6 warnings and 1 error generated.


vim +2474 drivers/gpu/drm/drm_modes.c

a631bf30eb914a Maxime Ripard         2022-11-14  2334  
1794d257fa7bab Chris Wilson          2011-04-17  2335  /**
f5aabb978d1dcd Daniel Vetter         2014-01-23  2336   * drm_mode_parse_command_line_for_connector - parse command line modeline for connector
f5aabb978d1dcd Daniel Vetter         2014-01-23  2337   * @mode_option: optional per connector mode option
f5aabb978d1dcd Daniel Vetter         2014-01-23  2338   * @connector: connector to parse modeline for
f5aabb978d1dcd Daniel Vetter         2014-01-23  2339   * @mode: preallocated drm_cmdline_mode structure to fill out
1794d257fa7bab Chris Wilson          2011-04-17  2340   *
f5aabb978d1dcd Daniel Vetter         2014-01-23  2341   * This parses @mode_option command line modeline for modes and options to
1e84dadb2762cd Thomas Zimmermann     2023-02-09  2342   * configure the connector.
f5aabb978d1dcd Daniel Vetter         2014-01-23  2343   *
f5aabb978d1dcd Daniel Vetter         2014-01-23  2344   * This uses the same parameters as the fb modedb.c, except for an extra
dbd124f013a23d Daniel Vetter         2018-02-19  2345   * force-enable, force-enable-digital and force-disable bit at the end::
1794d257fa7bab Chris Wilson          2011-04-17  2346   *
1794d257fa7bab Chris Wilson          2011-04-17  2347   *	<xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
1794d257fa7bab Chris Wilson          2011-04-17  2348   *
1bf4e09227c345 Maxime Ripard         2019-06-19  2349   * Additionals options can be provided following the mode, using a comma to
1bf4e09227c345 Maxime Ripard         2019-06-19  2350   * separate each option. Valid options can be found in
bff9e34c678552 Mauro Carvalho Chehab 2019-07-15  2351   * Documentation/fb/modedb.rst.
1bf4e09227c345 Maxime Ripard         2019-06-19  2352   *
f5aabb978d1dcd Daniel Vetter         2014-01-23  2353   * The intermediate drm_cmdline_mode structure is required to store additional
2a97acd6376922 Yannick Guerrini      2015-03-04  2354   * options from the command line modline like the force-enable/disable flag.
f5aabb978d1dcd Daniel Vetter         2014-01-23  2355   *
f5aabb978d1dcd Daniel Vetter         2014-01-23  2356   * Returns:
f5aabb978d1dcd Daniel Vetter         2014-01-23  2357   * True if a valid modeline has been parsed, false otherwise.
1794d257fa7bab Chris Wilson          2011-04-17  2358   */
1794d257fa7bab Chris Wilson          2011-04-17  2359  bool drm_mode_parse_command_line_for_connector(const char *mode_option,
c0898fca3fce00 Arnd Bergmann         2019-06-28  2360  					       const struct drm_connector *connector,
1794d257fa7bab Chris Wilson          2011-04-17  2361  					       struct drm_cmdline_mode *mode)
1794d257fa7bab Chris Wilson          2011-04-17  2362  {
1794d257fa7bab Chris Wilson          2011-04-17  2363  	const char *name;
7b1cce760afe38 Hans de Goede         2019-11-18  2364  	bool freestanding = false, parse_extras = false;
1bf4e09227c345 Maxime Ripard         2019-06-19  2365  	unsigned int bpp_off = 0, refresh_off = 0, options_off = 0;
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2366  	unsigned int mode_end = 0;
83e14ea3a64f00 Hans de Goede         2019-11-18  2367  	const char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
83e14ea3a64f00 Hans de Goede         2019-11-18  2368  	const char *options_ptr = NULL;
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2369  	char *bpp_end_ptr = NULL, *refresh_end_ptr = NULL;
a631bf30eb914a Maxime Ripard         2022-11-14  2370  	int len, ret;
1794d257fa7bab Chris Wilson          2011-04-17  2371  
d1fe276b5115f0 Hans de Goede         2019-11-18  2372  	memset(mode, 0, sizeof(*mode));
4e7a4a6fbdc669 Hans de Goede         2019-11-18  2373  	mode->panel_orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
4e7a4a6fbdc669 Hans de Goede         2019-11-18  2374  
d1fe276b5115f0 Hans de Goede         2019-11-18  2375  	if (!mode_option)
1794d257fa7bab Chris Wilson          2011-04-17  2376  		return false;
1794d257fa7bab Chris Wilson          2011-04-17  2377  
1794d257fa7bab Chris Wilson          2011-04-17  2378  	name = mode_option;
04fee895ef98ff Rolf Eike Beer        2011-06-15  2379  
90c258ba4a36f6 Maxime Ripard         2022-09-29  2380  	/* Locate the start of named options */
90c258ba4a36f6 Maxime Ripard         2022-09-29  2381  	options_ptr = strchr(name, ',');
90c258ba4a36f6 Maxime Ripard         2022-09-29  2382  	if (options_ptr)
90c258ba4a36f6 Maxime Ripard         2022-09-29  2383  		options_off = options_ptr - name;
90c258ba4a36f6 Maxime Ripard         2022-09-29  2384  	else
90c258ba4a36f6 Maxime Ripard         2022-09-29  2385  		options_off = strlen(name);
90c258ba4a36f6 Maxime Ripard         2022-09-29  2386  
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2387  	/* Try to locate the bpp and refresh specifiers, if any */
90c258ba4a36f6 Maxime Ripard         2022-09-29  2388  	bpp_ptr = strnchr(name, options_off, '-');
8b6e28ea0a51a7 Geert Uytterhoeven    2022-09-29  2389  	while (bpp_ptr && !isdigit(bpp_ptr[1]))
8b6e28ea0a51a7 Geert Uytterhoeven    2022-09-29  2390  		bpp_ptr = strnchr(bpp_ptr + 1, options_off, '-');
6a2d163756545a Hans de Goede         2019-11-18  2391  	if (bpp_ptr)
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2392  		bpp_off = bpp_ptr - name;
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2393  
90c258ba4a36f6 Maxime Ripard         2022-09-29  2394  	refresh_ptr = strnchr(name, options_off, '@');
7b1cce760afe38 Hans de Goede         2019-11-18  2395  	if (refresh_ptr)
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2396  		refresh_off = refresh_ptr - name;
04fee895ef98ff Rolf Eike Beer        2011-06-15  2397  
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2398  	/* Locate the end of the name / resolution, and parse it */
1bf4e09227c345 Maxime Ripard         2019-06-19  2399  	if (bpp_ptr) {
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2400  		mode_end = bpp_off;
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2401  	} else if (refresh_ptr) {
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2402  		mode_end = refresh_off;
1bf4e09227c345 Maxime Ripard         2019-06-19  2403  	} else if (options_ptr) {
1bf4e09227c345 Maxime Ripard         2019-06-19  2404  		mode_end = options_off;
cfb0881b8f621b Hans de Goede         2019-11-18  2405  		parse_extras = true;
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2406  	} else {
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2407  		mode_end = strlen(name);
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2408  		parse_extras = true;
04fee895ef98ff Rolf Eike Beer        2011-06-15  2409  	}
04fee895ef98ff Rolf Eike Beer        2011-06-15  2410  
a631bf30eb914a Maxime Ripard         2022-11-14  2411  	if (!mode_end)
a631bf30eb914a Maxime Ripard         2022-11-14  2412  		return false;
3764137906a5ac Maxime Ripard         2019-08-27  2413  
a631bf30eb914a Maxime Ripard         2022-11-14  2414  	ret = drm_mode_parse_cmdline_named_mode(name, mode_end, mode);
a631bf30eb914a Maxime Ripard         2022-11-14  2415  	if (ret < 0)
a631bf30eb914a Maxime Ripard         2022-11-14  2416  		return false;
a631bf30eb914a Maxime Ripard         2022-11-14  2417  
a631bf30eb914a Maxime Ripard         2022-11-14  2418  	/*
a631bf30eb914a Maxime Ripard         2022-11-14  2419  	 * Having a mode that starts by a letter (and thus is named) and
a631bf30eb914a Maxime Ripard         2022-11-14  2420  	 * an at-sign (used to specify a refresh rate) is disallowed.
a631bf30eb914a Maxime Ripard         2022-11-14  2421  	 */
a631bf30eb914a Maxime Ripard         2022-11-14  2422  	if (ret && refresh_ptr)
a631bf30eb914a Maxime Ripard         2022-11-14  2423  		return false;
3764137906a5ac Maxime Ripard         2019-08-27  2424  
7b1cce760afe38 Hans de Goede         2019-11-18  2425  	/* No named mode? Check for a normal mode argument, e.g. 1024x768 */
7b1cce760afe38 Hans de Goede         2019-11-18  2426  	if (!mode->specified && isdigit(name[0])) {
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2427  		ret = drm_mode_parse_cmdline_res_mode(name, mode_end,
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2428  						      parse_extras,
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2429  						      connector,
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2430  						      mode);
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2431  		if (ret)
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2432  			return false;
7b1cce760afe38 Hans de Goede         2019-11-18  2433  
1794d257fa7bab Chris Wilson          2011-04-17  2434  		mode->specified = true;
7b1cce760afe38 Hans de Goede         2019-11-18  2435  	}
7b1cce760afe38 Hans de Goede         2019-11-18  2436  
7b1cce760afe38 Hans de Goede         2019-11-18  2437  	/* No mode? Check for freestanding extras and/or options */
7b1cce760afe38 Hans de Goede         2019-11-18  2438  	if (!mode->specified) {
7b1cce760afe38 Hans de Goede         2019-11-18  2439  		unsigned int len = strlen(mode_option);
7b1cce760afe38 Hans de Goede         2019-11-18  2440  
7b1cce760afe38 Hans de Goede         2019-11-18  2441  		if (bpp_ptr || refresh_ptr)
7b1cce760afe38 Hans de Goede         2019-11-18  2442  			return false; /* syntax error */
7b1cce760afe38 Hans de Goede         2019-11-18  2443  
7b1cce760afe38 Hans de Goede         2019-11-18  2444  		if (len == 1 || (len >= 2 && mode_option[1] == ','))
7b1cce760afe38 Hans de Goede         2019-11-18  2445  			extra_ptr = mode_option;
7b1cce760afe38 Hans de Goede         2019-11-18  2446  		else
7b1cce760afe38 Hans de Goede         2019-11-18  2447  			options_ptr = mode_option - 1;
7b1cce760afe38 Hans de Goede         2019-11-18  2448  
7b1cce760afe38 Hans de Goede         2019-11-18  2449  		freestanding = true;
7b1cce760afe38 Hans de Goede         2019-11-18  2450  	}
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2451  
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2452  	if (bpp_ptr) {
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2453  		ret = drm_mode_parse_cmdline_bpp(bpp_ptr, &bpp_end_ptr, mode);
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2454  		if (ret)
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2455  			return false;
6a2d163756545a Hans de Goede         2019-11-18  2456  
6a2d163756545a Hans de Goede         2019-11-18  2457  		mode->bpp_specified = true;
1794d257fa7bab Chris Wilson          2011-04-17  2458  	}
1794d257fa7bab Chris Wilson          2011-04-17  2459  
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2460  	if (refresh_ptr) {
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2461  		ret = drm_mode_parse_cmdline_refresh(refresh_ptr,
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2462  						     &refresh_end_ptr, mode);
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2463  		if (ret)
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2464  			return false;
6a2d163756545a Hans de Goede         2019-11-18  2465  
6a2d163756545a Hans de Goede         2019-11-18  2466  		mode->refresh_specified = true;
1794d257fa7bab Chris Wilson          2011-04-17  2467  	}
1794d257fa7bab Chris Wilson          2011-04-17  2468  
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2469  	/*
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2470  	 * Locate the end of the bpp / refresh, and parse the extras
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2471  	 * if relevant
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2472  	 */
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2473  	if (bpp_ptr && refresh_ptr)
e08ab74bd4c7a5 Maxime Ripard         2019-06-19 @2474  		extra_ptr = max(bpp_end_ptr, refresh_end_ptr);
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2475  	else if (bpp_ptr)
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2476  		extra_ptr = bpp_end_ptr;
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2477  	else if (refresh_ptr)
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2478  		extra_ptr = refresh_end_ptr;
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2479  
c2ed3e94190181 Hans de Goede         2019-11-18  2480  	if (extra_ptr) {
c2ed3e94190181 Hans de Goede         2019-11-18  2481  		if (options_ptr)
c2ed3e94190181 Hans de Goede         2019-11-18  2482  			len = options_ptr - extra_ptr;
c2ed3e94190181 Hans de Goede         2019-11-18  2483  		else
c2ed3e94190181 Hans de Goede         2019-11-18  2484  			len = strlen(extra_ptr);
3aeeb13d899627 Maxime Ripard         2019-06-19  2485  
7b1cce760afe38 Hans de Goede         2019-11-18  2486  		ret = drm_mode_parse_cmdline_extra(extra_ptr, len, freestanding,
3aeeb13d899627 Maxime Ripard         2019-06-19  2487  						   connector, mode);
3aeeb13d899627 Maxime Ripard         2019-06-19  2488  		if (ret)
3aeeb13d899627 Maxime Ripard         2019-06-19  2489  			return false;
1bf4e09227c345 Maxime Ripard         2019-06-19  2490  	}
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2491  
1bf4e09227c345 Maxime Ripard         2019-06-19  2492  	if (options_ptr) {
739b200c2edcaa Hans de Goede         2019-11-18  2493  		ret = drm_mode_parse_cmdline_options(options_ptr + 1,
7b1cce760afe38 Hans de Goede         2019-11-18  2494  						     freestanding,
1bf4e09227c345 Maxime Ripard         2019-06-19  2495  						     connector, mode);
1bf4e09227c345 Maxime Ripard         2019-06-19  2496  		if (ret)
e08ab74bd4c7a5 Maxime Ripard         2019-06-19  2497  			return false;
1794d257fa7bab Chris Wilson          2011-04-17  2498  	}
1794d257fa7bab Chris Wilson          2011-04-17  2499  
1794d257fa7bab Chris Wilson          2011-04-17  2500  	return true;
1794d257fa7bab Chris Wilson          2011-04-17  2501  }
1794d257fa7bab Chris Wilson          2011-04-17  2502  EXPORT_SYMBOL(drm_mode_parse_command_line_for_connector);
1794d257fa7bab Chris Wilson          2011-04-17  2503  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* RE: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.
  2023-07-31 21:43   ` kernel test robot
@ 2023-08-01  8:45     ` David Laight
  0 siblings, 0 replies; 16+ messages in thread
From: David Laight @ 2023-08-01  8:45 UTC (permalink / raw)
  To: 'kernel test robot',
	'linux-kernel@vger.kernel.org', 'Andy Shevchenko',
	'Andrew Morton', 'Matthew Wilcox (Oracle)',
	'Christoph Hellwig', 'Jason A. Donenfeld'
  Cc: llvm, oe-kbuild-all, Linux Memory Management List

From: kernel test robot
> Sent: 31 July 2023 22:44
> 
> kernel test robot noticed the following build errors:
> 
> [auto build test ERROR on akpm-mm/mm-everything]
> [also build test ERROR on linus/master crng-random/master v6.5-rc4 next-20230731]
> [cannot apply to next-20230728]
...
> compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git
> f28c006a5895fc0e329fe15fead81e37457cb1d1)
> reproduce: (https://download.01.org/0day-ci/archive/20230801/202308010559.SEtfkzQU-
> lkp@intel.com/reproduce)
> 
....
> >> drivers/gpu/drm/drm_modes.c:2474:15: error: static_assert expression is not an integral constant
> expression
>                    extra_ptr = max(bpp_end_ptr, refresh_end_ptr);
>                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is really a bug in clang - fixed in 16.0.0.
In C (but probably not C++) '(void *)1' should be a compile-time constant.
Will be fixed in v3 of the patch.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* Re: [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants.
  2023-07-31 13:26   ` David Laight
@ 2023-08-01 16:02     ` Nick Desaulniers
  0 siblings, 0 replies; 16+ messages in thread
From: Nick Desaulniers @ 2023-08-01 16:02 UTC (permalink / raw)
  To: David Laight
  Cc: linux-kernel, Andy Shevchenko, Andrew Morton,
	Matthew Wilcox (Oracle),
	Christoph Hellwig, Jason A. Donenfeld, Nathan Chancellor, llvm

On Mon, Jul 31, 2023 at 6:27 AM David Laight <David.Laight@aculab.com> wrote:
>
> By the time I've done:
>
> #define __is_noneg_int(x)                                       \
>         __builtin_choose_expr(!__is_constexpr(x), false,        \
>                 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__))
>
> #define __is_signed(x)                                                         \
>        __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))),        \
>                is_signed_type(typeof(x)), 0)
>
> #define __types_ok(x, y)                                        \
>         (__is_signed(x) == __is_signed(y) ||                    \
>                 __is_signed((x) + 0) == __is_signed((y) + 0) || \
>                 __is_noneg_int(x) || __is_noneg_int(y))
>
> the error message for
>
> >       static_assert(__types_ok(x, y),                 \
> >               #op "(" #x ", " #y ") signedness error, fix types or consider " #op "_unsigned() before " #op "_t()"); \
>
> generated by clang 8.0.0 and later is similar to (see https://godbolt.org/z/jq613Gnsa):
>
> <source>:49:12: error: static assertion failed due to requirement '__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) || __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) || (__builtin_choose_expr(!(sizeof(int) == sizeof (*(8 ? ((void *)((long)(a) * 0L)) : (int *)8))), 0, __builtin_choose_expr(__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0), a, 0) >= 0 && (a) <= (int)(long)2147483647)) || (__builtin_choose_expr(!(sizeof(int) == sizeof (*(8 ? ((void *)((long)(2147483648U - 0) * 0L)) : (int *)8))), 0, __builtin_choose_expr(__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0), 2147483648U - 0, 0) >= 0 && (2147483648U - 0) <= (unsigned int)(long)2147483647))': min(a, 0x80000000u - 0) signedness error, fix types or consider min_unsigned() before min_t()
>
> Repeating the expression seems somewhat sub-optimal!
> Surely it shouldn't be outputting the expansion of the
> input when an error message is supplied?
>
> Is there any (sane) way to stop it being that verbose?

No, but we can probably change that in clang. Filed:
https://github.com/llvm/llvm-project/issues/64310

>
>         David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)



-- 
Thanks,
~Nick Desaulniers

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

end of thread, other threads:[~2023-08-01 16:02 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-28 14:49 [PATCH next v2 0/5] minmax: Relax type checks in min() and max() David Laight
2023-07-28 14:50 ` [PATCH next v2 1/5] minmax: Add min_unsigned(a, b) and max_unsigned(a, b) David Laight
2023-07-28 14:51 ` [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness David Laight
2023-07-29  2:00   ` kernel test robot
2023-07-30 14:55     ` David Laight
2023-07-30 17:05       ` Nathan Chancellor
2023-07-30 17:33         ` David Laight
2023-07-31 21:43   ` kernel test robot
2023-08-01  8:45     ` David Laight
2023-07-28 14:52 ` [PATCH next v2 3/5] minmax: Fix indentation of __cmp_once() and __clamp_once() David Laight
2023-07-28 14:52 ` [PATCH next v2 4/5] minmax: Allow comparisons of 'int' against 'unsigned char/short' David Laight
2023-07-28 14:53 ` [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants David Laight
2023-07-28 21:43   ` kernel test robot
2023-07-30 16:55     ` David Laight
2023-07-31 13:26   ` David Laight
2023-08-01 16:02     ` Nick Desaulniers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.