Re: [PATCH] m68k: hash: Use lower_16_bits() helper
From: Heiko Stuebner
Date: Thu Jun 04 2026 - 04:52:08 EST
Am Donnerstag, 4. Juni 2026, 09:54:23 Mitteleuropäische Sommerzeit schrieb Geert Uytterhoeven:
> When building for m68k with CONFIG_M68000=y and C=1:
>
> drivers/clk/rockchip/clk-rk3528.c: note: in included file (through include/linux/hash.h, include/linux/slab.h):
> arch/m68k/include/asm/hash.h:57:24: warning: cast truncates bits from constant value (18720 becomes 8720)
> arch/m68k/include/asm/hash.h:57:24: warning: cast truncates bits from constant value (1e8e8 becomes e8e8)
>
> Sparse does not realize the truncation is intentional.
> Make this explicit by using the lower_16_bits() helper instead, which
> also masks the unwanted bits.
>
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Closes: https://lore.kernel.org/oe-kbuild-all/202605191434.PQkj2Rki-lkp@xxxxxxxxx/
> Reported-by: Heiko Stuebner <heiko@xxxxxxxxx>
> Closes: https://lore.kernel.org/20260603213726.1025094-1-heiko@xxxxxxxxx/
> Signed-off-by: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
While I have no clue about m68k, lower_16_bits() does the correct thing
it seems, so
Reviewed-by: Heiko Stuebner <heiko@xxxxxxxxx>
and thanks for providing the correct fix for the core issue, so
other compile-test cases also won't create those warning.
Heiko
> ---
> No change in generated code.
>
> arch/m68k/include/asm/hash.h | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/m68k/include/asm/hash.h b/arch/m68k/include/asm/hash.h
> index 6d0d0c893f16dd49..6dadf493706632f5 100644
> --- a/arch/m68k/include/asm/hash.h
> +++ b/arch/m68k/include/asm/hash.h
> @@ -2,6 +2,8 @@
> #ifndef _ASM_HASH_H
> #define _ASM_HASH_H
>
> +#include <linux/wordpart.h>
> +
> /*
> * If CONFIG_M68000=y (original mc68000/010), this file is #included
> * to work around the lack of a MULU.L instruction.
> @@ -54,7 +56,7 @@ static inline u32 __attribute_const__ __hash_32(u32 x)
> : "=&d,d" (a), "=&r,r" (b)
> : "r,roi?" (x)); /* a+b = x*0x8647 */
>
> - return ((u16)(x*0x61c8) << 16) + a + b;
> + return (lower_16_bits(x * 0x61c8) << 16) + a + b;
> }
>
> #endif /* _ASM_HASH_H */
>