diff mbox series

power: vexpress: fix -Wvoid-pointer-to-enum-cast warning

Message ID 20230814-void-drivers-power-reset-vexpress-poweroff-v1-1-c3d9b0107e5d@google.com (mailing list archive)
State New, archived
Headers show
Series power: vexpress: fix -Wvoid-pointer-to-enum-cast warning | expand

Commit Message

Justin Stitt Aug. 14, 2023, 10:21 p.m. UTC
When building with clang 18 I see the following warning:
|       drivers/power/reset/vexpress-poweroff.c:124:10: warning: cast to smaller integer type 'enum vexpress_reset_func' from 'const void *' [-Wvoid-pointer-to-enum-cast]
|         124 |         switch ((enum vexpress_reset_func)match->data) {

This is due to the fact that `match->data` is a void* while `enum vexpress_reset_func`
has the size of an int. This leads to truncation and possible data loss.

Link: https://github.com/ClangBuiltLinux/linux/issues/1910
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Note: In this case, it seems unlikely that any data loss is occurring
since `enum vexpress_reset_func` only has a few fields enumerated from 0.
---
 drivers/power/reset/vexpress-poweroff.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


---
base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
change-id: 20230814-void-drivers-power-reset-vexpress-poweroff-ca762488cf1f

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

Comments

Sudeep Holla Aug. 18, 2023, 9:44 a.m. UTC | #1
On Mon, Aug 14, 2023 at 10:21:51PM +0000, Justin Stitt wrote:
> When building with clang 18 I see the following warning:
> |       drivers/power/reset/vexpress-poweroff.c:124:10: warning: cast to smaller integer type 'enum vexpress_reset_func' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> |         124 |         switch ((enum vexpress_reset_func)match->data) {
> 
> This is due to the fact that `match->data` is a void* while `enum vexpress_reset_func`
> has the size of an int. This leads to truncation and possible data loss.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> Reported-by: Nathan Chancellor <nathan@kernel.org>

Hi Sebastian,

I am assuming you will pick this up.

Acked-by: Sudeep Holla <sudeep.holla@arm.com>
Sebastian Reichel Sept. 12, 2023, 6:19 p.m. UTC | #2
On Mon, 14 Aug 2023 22:21:51 +0000, Justin Stitt wrote:
> When building with clang 18 I see the following warning:
> |       drivers/power/reset/vexpress-poweroff.c:124:10: warning: cast to smaller integer type 'enum vexpress_reset_func' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> |         124 |         switch ((enum vexpress_reset_func)match->data) {
> 
> This is due to the fact that `match->data` is a void* while `enum vexpress_reset_func`
> has the size of an int. This leads to truncation and possible data loss.
> 
> [...]

Applied, thanks!

[1/1] power: vexpress: fix -Wvoid-pointer-to-enum-cast warning
      commit: 4ec7b666fb4247bc6b9cdc84fa753d8dc2994d25

Best regards,
diff mbox series

Patch

diff --git a/drivers/power/reset/vexpress-poweroff.c b/drivers/power/reset/vexpress-poweroff.c
index 447ffdacddf9..17064d7b19f6 100644
--- a/drivers/power/reset/vexpress-poweroff.c
+++ b/drivers/power/reset/vexpress-poweroff.c
@@ -121,7 +121,7 @@  static int vexpress_reset_probe(struct platform_device *pdev)
 		return PTR_ERR(regmap);
 	dev_set_drvdata(&pdev->dev, regmap);
 
-	switch ((enum vexpress_reset_func)match->data) {
+	switch ((uintptr_t)match->data) {
 	case FUNC_SHUTDOWN:
 		vexpress_power_off_device = &pdev->dev;
 		pm_power_off = vexpress_power_off;