mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] mtd: maps: fix -Wvoid-pointer-to-enum-cast warning
@ 2023-08-16 18:26 Justin Stitt
  2023-08-18 14:40 ` Miquel Raynal
  0 siblings, 1 reply; 2+ messages in thread
From: Justin Stitt @ 2023-08-16 18:26 UTC (permalink / raw)
  To: Linus Walleij, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Nathan Chancellor, Nick Desaulniers,
	Tom Rix
  Cc: Krzysztof Kozlowski, linux-arm-kernel, linux-mtd, linux-kernel,
	llvm, Justin Stitt

When building with clang 18 I see the following warning:
|       drivers/mtd/maps/physmap-versatile.c:209:25: warning: cast to smaller
|               integer type 'enum versatile_flashprot' from 'const void *' [-Wvoid-pointer-to-enum-cast]
|         209 |                 versatile_flashprot = (enum versatile_flashprot)devid->data;

This is due to the fact that `devid->data` is a void* while `enum versatile_flashprot`
has the size of an int.

Cast `devid->data` to a uintptr_t to silence the above warning for clang
builds using W=1.

Link: https://github.com/ClangBuiltLinux/linux/issues/1910
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Changes in v2:
- Use more accurate commit message (thanks Krzysztof)
- Link to v1: https://lore.kernel.org/r/20230815-void-drivers-mtd-maps-physmap-versatile-v1-1-ba6fc86d5e4e@google.com
---
 drivers/mtd/maps/physmap-versatile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/maps/physmap-versatile.c b/drivers/mtd/maps/physmap-versatile.c
index a1b8b7b25f88..d65cf8833771 100644
--- a/drivers/mtd/maps/physmap-versatile.c
+++ b/drivers/mtd/maps/physmap-versatile.c
@@ -206,7 +206,7 @@ int of_flash_probe_versatile(struct platform_device *pdev,
 		if (!sysnp)
 			return -ENODEV;
 
-		versatile_flashprot = (enum versatile_flashprot)devid->data;
+		versatile_flashprot = (uintptr_t)devid->data;
 		rmap = syscon_node_to_regmap(sysnp);
 		of_node_put(sysnp);
 		if (IS_ERR(rmap))

---
base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
change-id: 20230815-void-drivers-mtd-maps-physmap-versatile-2270fe7fdf16

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


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

* Re: [PATCH v2] mtd: maps: fix -Wvoid-pointer-to-enum-cast warning
  2023-08-16 18:26 [PATCH v2] mtd: maps: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
@ 2023-08-18 14:40 ` Miquel Raynal
  0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2023-08-18 14:40 UTC (permalink / raw)
  To: Justin Stitt, Linus Walleij, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Nathan Chancellor, Nick Desaulniers,
	Tom Rix
  Cc: Krzysztof Kozlowski, linux-arm-kernel, linux-mtd, linux-kernel, llvm

On Wed, 2023-08-16 at 18:26:44 UTC, Justin Stitt wrote:
> When building with clang 18 I see the following warning:
> |       drivers/mtd/maps/physmap-versatile.c:209:25: warning: cast to smaller
> |               integer type 'enum versatile_flashprot' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> |         209 |                 versatile_flashprot = (enum versatile_flashprot)devid->data;
> 
> This is due to the fact that `devid->data` is a void* while `enum versatile_flashprot`
> has the size of an int.
> 
> Cast `devid->data` to a uintptr_t to silence the above warning for clang
> builds using W=1.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Justin Stitt <justinstitt@google.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

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

end of thread, other threads:[~2023-08-18 14:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-16 18:26 [PATCH v2] mtd: maps: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
2023-08-18 14:40 ` Miquel Raynal

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

all inboxes | Powered by JetHome®