[PATCH] i2c: pxa: fix clang -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/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@xxxxxxxxxx>
Signed-off-by: Justin Stitt <justinstitt@xxxxxxxxxx>
---
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@xxxxxxxxxx>




[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux