public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: rawnand: fix -Wvoid-pointer-to-enum-cast warning
@ 2023-08-15 20:58 Justin Stitt
  2023-08-17  8:43 ` Miquel Raynal
  0 siblings, 1 reply; 2+ messages in thread
From: Justin Stitt @ 2023-08-15 20:58 UTC (permalink / raw)
  To: Stefan Agner, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Nathan Chancellor, Nick Desaulniers, Tom Rix
  Cc: linux-mtd, linux-kernel, llvm, Justin Stitt

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.

Link: https://github.com/ClangBuiltLinux/linux/issues/1910
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Justin Stitt <justinstitt@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.
---
 drivers/mtd/nand/raw/vf610_nfc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c
index 86522048e271..11d996dc655d 100644
--- a/drivers/mtd/nand/raw/vf610_nfc.c
+++ b/drivers/mtd/nand/raw/vf610_nfc.c
@@ -850,7 +850,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
 		goto err_disable_clk;
 	}
 
-	nfc->variant = (enum vf610_nfc_variant)of_id->data;
+	nfc->variant = (uintptr_t)of_id->data;
 
 	for_each_available_child_of_node(nfc->dev->of_node, child) {
 		if (of_device_is_compatible(child, "fsl,vf610-nfc-nandcs")) {

---
base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
change-id: 20230815-void-drivers-mtd-nand-raw-vf610_nfc-6c358f424b8a

Best regards,
--
Justin Stitt <justinstitt@google.com>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mtd: rawnand: fix -Wvoid-pointer-to-enum-cast warning
  2023-08-15 20:58 [PATCH] mtd: rawnand: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
@ 2023-08-17  8:43 ` Miquel Raynal
  0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2023-08-17  8:43 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Stefan Agner, Richard Weinberger, Vignesh Raghavendra,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-mtd,
	linux-kernel, llvm

Hi Justin,

justinstitt@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@kernel.org>
> Signed-off-by: Justin Stitt <justinstitt@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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-17  8:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-15 20:58 [PATCH] mtd: rawnand: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
2023-08-17  8:43 ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox