mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] minmax.h: update the stale 'x' versus 'ux' comment
@ 2026-08-17 12:16 Zhan Xusheng
  2026-08-29 23:42 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Zhan Xusheng @ 2026-08-17 12:16 UTC (permalink / raw)
  To: David Laight, Andrew Morton
  Cc: H . Peter Anvin, zhanxusheng, linux-kernel, Zhan Xusheng

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


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

* Re: [PATCH] minmax.h: update the stale 'x' versus 'ux' comment
  2026-08-17 12:16 [PATCH] minmax.h: update the stale 'x' versus 'ux' comment Zhan Xusheng
@ 2026-08-29 23:42 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2026-08-29 23:42 UTC (permalink / raw)
  To: Zhan Xusheng; +Cc: David Laight, H . Peter Anvin, zhanxusheng, linux-kernel

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


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

end of thread, other threads:[~2026-08-29 23:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-17 12:16 [PATCH] minmax.h: update the stale 'x' versus 'ux' comment Zhan Xusheng
2026-08-29 23:42 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®