[PATCH] minmax.h: update the stale 'x' versus 'ux' comment

Zhan Xusheng posted 1 patch 1 month, 1 week ago
include/linux/minmax.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] minmax.h: update the stale 'x' versus 'ux' comment
Posted by Zhan Xusheng 1 month, 1 week ago
From: Zhan Xusheng <zhanxusheng1024@gmail.com>

From: Zhan Xusheng <zhanxusheng@xiaomi.com>

Commit b280bb27a9f7 ("minmax.h: reduce the #define expansion of min(),
max() and clamp()") made __sign_use(), __is_nonneg() and __types_ok() take
only 'ux', and commit a5743f32baec ("minmax.h: use BUILD_BUG_ON_MSG() for
the lo < hi test in clamp()") did the same for the clamp() limit test.  The
comment describing the old split was added one patch earlier and was never
updated.

'ux' now carries the value check too, since __is_nonneg() tests it rather
than the original expression, and nothing here looks at the value of 'x'
any more: it is expanded only to initialise 'ux' and in the error message,
as the first of those changes intended.

Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
 include/linux/minmax.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index a0158db54a04..5ef4d58c0c42 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -38,9 +38,9 @@
  * Note that 'x' is the original expression, and 'ux' is the unique variable
  * that contains the value.
  *
- * We use 'ux' for pure type checking, and 'x' for when we need to look at the
- * value (but without evaluating it for side effects!
- * Careful to only ever evaluate it with sizeof() or __builtin_constant_p() etc).
+ * We use 'ux' for both the type and the value checks, so 'x' itself is only
+ * expanded twice: once to initialise 'ux', and once quoted in the error
+ * message.
  *
  * Pointers end up being checked by the normal C type rules at the actual
  * comparison, and these expressions only need to be careful to not cause
-- 
2.43.0
Re: [PATCH] minmax.h: update the stale 'x' versus 'ux' comment
Posted by Andrew Morton 4 weeks, 1 day ago
On Mon, 17 Aug 2026 20:16:13 +0800 Zhan Xusheng <zhanxusheng1024@gmail.com> wrote:

> From: Zhan Xusheng <zhanxusheng1024@gmail.com>
> 
> From: Zhan Xusheng <zhanxusheng@xiaomi.com>

Well that's confusing ;)

I'll assume @xiaomi.com was intended.

> Commit b280bb27a9f7 ("minmax.h: reduce the #define expansion of min(),
> max() and clamp()") made __sign_use(), __is_nonneg() and __types_ok() take
> only 'ux', and commit a5743f32baec ("minmax.h: use BUILD_BUG_ON_MSG() for
> the lo < hi test in clamp()") did the same for the clamp() limit test.  The
> comment describing the old split was added one patch earlier and was never
> updated.
> 
> 'ux' now carries the value check too, since __is_nonneg() tests it rather
> than the original expression, and nothing here looks at the value of 'x'
> any more: it is expanded only to initialise 'ux' and in the error message,
> as the first of those changes intended.
> 

Thanks.

> --- a/include/linux/minmax.h
> +++ b/include/linux/minmax.h
> @@ -38,9 +38,9 @@
>   * Note that 'x' is the original expression, and 'ux' is the unique variable
>   * that contains the value.
>   *
> - * We use 'ux' for pure type checking, and 'x' for when we need to look at the
> - * value (but without evaluating it for side effects!
> - * Careful to only ever evaluate it with sizeof() or __builtin_constant_p() etc).
> + * We use 'ux' for both the type and the value checks, so 'x' itself is only
> + * expanded twice: once to initialise 'ux', and once quoted in the error
> + * message.
>   *
>   * Pointers end up being checked by the normal C type rules at the actual
>   * comparison, and these expressions only need to be careful to not cause