Skip to contentSkip to conversation

mtd: maps: fix -Wvoid-pointer-to-enum-cast warning

PATCH Applied Justin Stitt 2 participants 2 messages Aug 16, 2023 – Aug 18, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mtd: maps: fix -Wvoid-pointer-to-enum-cast warning

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.

---
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(-)
drivers/mtd/maps/physmap-versatile.c +1 -1
index a1b8b7b25f88..d65cf8833771 100644
@@ -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 <[email protected]>

maintainer Applied
#1 lore raw
Quoted 8 lines · 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.

Quoted 6 lines

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

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

Miquel