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

From: Justin Stitt
Date: Mon Aug 14 2023 - 18:12:10 EST


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>