[PATCH 1/3] cmd: ufetch: Fix type mismatch on 32-bit

Caleb Connolly caleb.connolly at linaro.org
Mon Dec 9 15:58:10 CET 2024


Hi J,

Thanks for the patch!

On 05/12/2024 19:35, J. Neuschäfer via B4 Relay wrote:
> From: "J. Neuschäfer" <j.ne at posteo.net>
> 
> On 32-bit architectures, LAST_LINE (_LAST_LINE - 1UL) is 64 bits long,
> but size_t (from ARRAY_SIZE(...)) is 32 bits. This results in a warning
> because the max() macro expects the same type on both sides:
> 
> cmd/ufetch.c: In function ‘do_ufetch’:
> include/linux/kernel.h:179:24: warning: comparison of distinct pointer types lacks a cast [-Wcompare-distinct-pointer-types]
>   179 |         (void) (&_max1 == &_max2);              \
>       |                        ^~
> cmd/ufetch.c:92:25: note: in expansion of macro ‘max’
>    92 |         int num_lines = max(LAST_LINE + 1, ARRAY_SIZE(logo_lines));
>       |                         ^~~
> 
> Fix this by casting LAST_LINE to size_t.
> 
> Signed-off-by: J. Neuschäfer <j.ne at posteo.net>

Reviewed-by: Caleb Connolly <caleb.connolly at linaro.org>
> ---
>  cmd/ufetch.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/cmd/ufetch.c b/cmd/ufetch.c
> index 0b825d7e8c75f3b18933d3e3f77e5f40f2c7b658..5f3ef847b268dc384271fc6774720e5fd2337157 100644
> --- a/cmd/ufetch.c
> +++ b/cmd/ufetch.c
> @@ -89,7 +89,7 @@ enum output_lines {
>  static int do_ufetch(struct cmd_tbl *cmdtp, int flag, int argc,
>  		     char *const argv[])
>  {
> -	int num_lines = max(LAST_LINE + 1, ARRAY_SIZE(logo_lines));
> +	int num_lines = max((size_t)LAST_LINE + 1, ARRAY_SIZE(logo_lines));
>  	const char *model, *compatible;
>  	char *ipaddr;
>  	int n_cmds, n_cpus = 0, ret, compatlen;
> 

-- 
// Caleb (they/them)



More information about the U-Boot mailing list