public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: pxa: fix clang -Wvoid-pointer-to-enum-cast warning
@ 2023-08-16 19:48 Justin Stitt
  2023-08-25 22:17 ` Wolfram Sang
  0 siblings, 1 reply; 6+ messages in thread
From: Justin Stitt @ 2023-08-16 19:48 UTC (permalink / raw)
  To: Andi Shyti, Nathan Chancellor, Nick Desaulniers, Tom Rix
  Cc: linux-i2c, linux-kernel, llvm, Justin Stitt

When building with clang 18 I see the following warning:
|       drivers/i2c/busses/i2c-pxa.c:1267:15: warning: cast to smaller integer
|       type 'enum pxa_i2c_types' from 'const void *' [-Wvoid-pointer-to-enum-cast]
|        1267 |         *i2c_types = (enum pxa_i2c_types)(of_id->data);

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

Cast `of_id->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>
---
Note: I think something like this may be more readable:
| 	*i2c_types = (enum pxa_i2c_types)(uintptr_t)of_id->data;

Thoughts on this approach against the one present in this patch?
---
 drivers/i2c/busses/i2c-pxa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 937f7eebe906..20d1132d3d69 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -1264,7 +1264,7 @@ static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c,
 	i2c->use_pio = of_property_read_bool(np, "mrvl,i2c-polling");
 	i2c->fast_mode = of_property_read_bool(np, "mrvl,i2c-fast-mode");
 
-	*i2c_types = (enum pxa_i2c_types)(of_id->data);
+	*i2c_types = (uintptr_t)of_id->data;
 
 	return 0;
 }

---
base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
change-id: 20230816-void-drivers-i2c-busses-i2c-pxa-aaf94f5c39e0

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


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

end of thread, other threads:[~2023-09-03 10:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-16 19:48 [PATCH] i2c: pxa: fix clang -Wvoid-pointer-to-enum-cast warning Justin Stitt
2023-08-25 22:17 ` Wolfram Sang
2023-08-25 22:49   ` Justin Stitt
2023-08-25 22:52     ` Nick Desaulniers
2023-08-25 22:59     ` Wolfram Sang
2023-09-03 10:35       ` Andi Shyti

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