Re: [PATCH] soc: renesas: rmobile-sysc: fix -Wvoid-pointer-to-enum-cast warning

From: Geert Uytterhoeven
Date: Wed Aug 30 2023 - 15:31:20 EST


Hi Justin,

On Tue, Aug 15, 2023 at 12:11 AM Justin Stitt <justinstitt@xxxxxxxxxx> wrote:
> When building with clang 18 I see the following warning:
> | drivers/soc/renesas/rmobile-sysc.c:193:22: warning: cast to smaller integer
> | type 'enum pd_types' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> | 193 | add_special_pd(np, (enum pd_types)id->data);
>
> This is due to the fact that `id->data` is a void* and `enum pd_types`
> has the size of an integer. This cast from pointer-width to int-width
> causes truncation and possible data loss. Instead, cast to `uintptr_t`
> which has the same width as void*.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> Reported-by: Nathan Chancellor <nathan@xxxxxxxxxx>

scripts/checkpatch.pl:

WARNING: Reported-by: should be immediately followed by Closes:
with a URL to the report

Hence changing the Link: tag to a Closes: tag.

> Signed-off-by: Justin Stitt <justinstitt@xxxxxxxxxx>
> ---
> Note: It should be noted that there is likely no data loss occurring in
> this case since the enum only has a few fields. The narrowing cast from
> pointer to int will not lose any data.

Indeed, the theoretical narrowing could only happen on a 64-bit
platform, while this driver is only used on arm32.

Reviewed-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
i.e. will queue in renesas-devel for v6.7.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds