[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aR8xdGKNibyL94jX@yury>
Date: Thu, 20 Nov 2025 10:19:23 -0500
From: Yury Norov <yury.norov@...il.com>
To: david.laight.linux@...il.com
Cc: linux-kernel@...r.kernel.org
Subject: Re: [PATCH 32/44] nodemask: use min() instead of min_t()
On Wed, Nov 19, 2025 at 10:41:28PM +0000, david.laight.linux@...il.com wrote:
> From: David Laight <david.laight.linux@...il.com>
>
> min_t(unsigned int, a, b) casts an 'unsigned long' to 'unsigned int'.
> Use min(a, b) instead as it promotes any 'unsigned int' to 'unsigned long'
> and so cannot discard significant bits.
>
> In this case the 'unsigned long' value is small enough that the result
> is ok.
>
> Detected by an extra check added to min_t().
>
> Signed-off-by: David Laight <david.laight.linux@...il.com>
Applied, thanks.
> ---
> include/linux/nodemask.h | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
> index 7ad1f5c7407e..bd38648c998d 100644
> --- a/include/linux/nodemask.h
> +++ b/include/linux/nodemask.h
> @@ -245,18 +245,18 @@ static __always_inline int __nodes_weight(const nodemask_t *srcp, unsigned int n
> }
>
> /* FIXME: better would be to fix all architectures to never return
> - > MAX_NUMNODES, then the silly min_ts could be dropped. */
> + > MAX_NUMNODES, then the silly min()s could be dropped. */
>
> #define first_node(src) __first_node(&(src))
> static __always_inline unsigned int __first_node(const nodemask_t *srcp)
> {
> - return min_t(unsigned int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES));
> + return min(MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES));
> }
>
> #define next_node(n, src) __next_node((n), &(src))
> static __always_inline unsigned int __next_node(int n, const nodemask_t *srcp)
> {
> - return min_t(unsigned int, MAX_NUMNODES, find_next_bit(srcp->bits, MAX_NUMNODES, n+1));
> + return min(MAX_NUMNODES, find_next_bit(srcp->bits, MAX_NUMNODES, n+1));
> }
>
> /*
> @@ -293,8 +293,7 @@ static __always_inline void init_nodemask_of_node(nodemask_t *mask, int node)
> #define first_unset_node(mask) __first_unset_node(&(mask))
> static __always_inline unsigned int __first_unset_node(const nodemask_t *maskp)
> {
> - return min_t(unsigned int, MAX_NUMNODES,
> - find_first_zero_bit(maskp->bits, MAX_NUMNODES));
> + return min(MAX_NUMNODES, find_first_zero_bit(maskp->bits, MAX_NUMNODES));
> }
>
> #define NODE_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(MAX_NUMNODES)
> --
> 2.39.5
>
Powered by blists - more mailing lists