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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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>
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.
---
 drivers/soc/renesas/rmobile-sysc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/soc/renesas/rmobile-sysc.c b/drivers/soc/renesas/rmobile-sysc.c
index 912daadaa10d..0b77f37787d5 100644
--- a/drivers/soc/renesas/rmobile-sysc.c
+++ b/drivers/soc/renesas/rmobile-sysc.c
@@ -190,7 +190,7 @@ static void __init get_special_pds(void)
 
 	/* PM domains containing other special devices */
 	for_each_matching_node_and_match(np, special_ids, &id)
-		add_special_pd(np, (enum pd_types)id->data);
+		add_special_pd(np, (uintptr_t)id->data);
 }
 
 static void __init put_special_pds(void)

---
base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
change-id: 20230814-void-drivers-soc-renesas-rmobile-sysc-98150a2571cc

Best regards,
--
Justin Stitt <justinstitt@xxxxxxxxxx>




[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux