[PATCH] mtd: rawnand: fix -Wvoid-pointer-to-enum-cast warning

Miquel Raynal miquel.raynal at bootlin.com
Thu Aug 17 01:43:16 PDT 2023


Hi Justin,

justinstitt at google.com wrote on Tue, 15 Aug 2023 20:58:47 +0000:

> When building with clang 18 I see the following warning:
> |       drivers/mtd/nand/raw/vf610_nfc.c:853:17: warning: cast to smaller integer
> |               type 'enum vf610_nfc_variant' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> |         853 |         nfc->variant = (enum vf610_nfc_variant)of_id->data;
> 
> This is due to the fact that `of_id->data` is a void* while `enum
> vf610_nfc_variant` has the size of an int. This leads to truncation and
> possible data loss.

Can you please update this commit log to what Krzysztof suggested in
the "mtd: maps: fix -W<foo> warning" thread?

> Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> Reported-by: Nathan Chancellor <nathan at kernel.org>
> Signed-off-by: Justin Stitt <justinstitt at google.com>
> ---
> Note: There is likely no data loss actually occurring here due to the
> fact that `enum vf610_nfc_variant` only has a few fields which are not
> nearly large enough to cause data loss. This patch helps towards the
> goal of eventually enabling this warning.
> 
> Also, should we use `unsigned long` here instead of `uintptr_t`? I've
> seen maintainers request both and I'm flipping a coin here.

I'm fine with uintptr_t.

Thanks,
Miquèl



More information about the linux-mtd mailing list