ipmi_si: fix -Wvoid-pointer-to-enum-cast warning
PATCH 1/1 ipmi_si: fix -Wvoid-pointer-to-enum-cast warning
With W=1 we see the following warning:
| drivers/char/ipmi/ipmi_si_platform.c:272:15: error: \ | cast to smaller integer type 'enum si_type' from \ | 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast] | 272 | io.si_type = (enum si_type) match->data; | | ^~~~~~~~~~~~~~~~~~~~~~~~~~
This is due to the fact that the si_type enum members are int-width and a cast from pointer-width down to int will cause truncation and possible data loss. Although in this case si_type has only a few enumerated fields and thus there is likely no data loss occurring. Nonetheless, this patch is necessary to the goal of promoting this warning out of W=1.
---
Note:
Arnd had mentioned that there perhaps may be some semantic differences between GCC and Clang regarding this warning or family of warnings. For now, this patch (and others following) will yield less noisy W=1 builds and hopefully materialize into this warning getting promoted out of W=1 to an always-on warning.
--- drivers/char/ipmi/ipmi_si_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/ipmi/ipmi_si_platform.c +1 -1
@@ -269,7 +269,7 @@ static int of_ipmi_probe(struct platform_device *pdev) }memset (&io,0 ,sizeof (io)); - io.si_type = (enum si_type ) match->data; + io.si_type = (unsigned long ) match->data; io.addr_source =SI_DEVICETREE ; io.irq_setup = ipmi_std_irq_setup;
---
base-commit: c1a515d3c0270628df8ae5f5118ba859b85464a2
change-id: 20230809-cbl-1902-7532a747b731
Best regards,
--
Justin Stitt <[email protected]>
Quoted 35 lines · Justin Stitt
With W=1 we see the following warning:
| drivers/char/ipmi/ipmi_si_platform.c:272:15: error: \ | cast to smaller integer type 'enum si_type' from \ | 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast] | 272 | io.si_type = (enum si_type) match->data; | | ^~~~~~~~~~~~~~~~~~~~~~~~~~This is due to the fact that the
si_typeenum members are int-width and a cast from pointer-width down to int will cause truncation and possible data loss. Although in this casesi_typehas only a few enumerated fields and thus there is likely no data loss occurring. Nonetheless, this patch is necessary to the goal of promoting this warning out of W=1.Reported-by kernel test robot <[email protected]>Signed-off-by Justin Stitt <[email protected]>---
Note:
Arnd had mentioned that there perhaps may be some semantic differences between GCC and Clang regarding this warning or family of warnings. For now, this patch (and others following) will yield less noisy W=1 builds and hopefully materialize into this warning getting promoted out of W=1 to an always-on warning.--- drivers/char/ipmi/ipmi_si_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/char/ipmi/ipmi_si_platform.c +0
-0
drivers/char/ipmi/ipmi_si_platform.c static int of_ipmi_probe(struct platform_device *pdev) · line 272
Quoted 5 lines
drivers/char/ipmi/ipmi_si_platform.c +1
-1@@ -269,7 +269,7 @@ static int of_ipmi_probe(struct platform_device *pdev) }memset (&io,0 ,sizeof (io)); - io.si_type = (enum si_type ) match->data; + io.si_type = (unsigned long ) match->data;
Wouldn't you want to use intptr_t or uintptr_t?
-corey
Quoted 12 lines
drivers/char/ipmi/ipmi_si_platform.c +0
-1io.addr_source =SI_DEVICETREE ; io.irq_setup = ipmi_std_irq_setup; ---base-commit:
c1a515d3c0270628df8ae5f5118ba859b85464a2
change-id: 20230809-cbl-1902-7532a747b731Best regards,
--
Justin Stitt <[email protected]>
From: Corey Minyard
Quoted 1 line
Sent: 11 August 2023 21:27
...
Quoted 5 lines
drivers/char/ipmi/ipmi_si_platform.c static int of_ipmi_probe(struct platform_device *pdev) · line 272
Quoted 3 lines
drivers/char/ipmi/ipmi_si_platform.c +1
-1memset (&io,0 ,sizeof (io)); - io.si_type = (enum si_type ) match->data; + io.si_type = (unsigned long ) match->data;Wouldn't you want to use
intptr_toruintptr_t?
The kernel tends to use 'long' for the same reason it doesn't use uint8_t.
Although I'm sure the correct/better fix is to either add variants of the match/lookup functions that return (say) unsigned long or change all the drivers to allocate a structure that contains the required value.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 7 lines · Justin Stitt
With W=1 we see the following warning:
| drivers/char/ipmi/ipmi_si_platform.c:272:15: error: \ | cast to smaller integer type 'enum si_type' from \ | 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast] | 272 | io.si_type = (enum si_type) match->data; | | ^~~~~~~~~~~~~~~~~~~~~~~~~~
Ok, this is included in my tree. Thanks.
-corey
Quoted 45 lines
This is due to the fact that the
si_typeenum members are int-width and a cast from pointer-width down to int will cause truncation and possible data loss. Although in this casesi_typehas only a few enumerated fields and thus there is likely no data loss occurring. Nonetheless, this patch is necessary to the goal of promoting this warning out of W=1.Reported-by kernel test robot <[email protected]>Signed-off-by Justin Stitt <[email protected]>---
Note:
Arnd had mentioned that there perhaps may be some semantic differences between GCC and Clang regarding this warning or family of warnings. For now, this patch (and others following) will yield less noisy W=1 builds and hopefully materialize into this warning getting promoted out of W=1 to an always-on warning.--- drivers/char/ipmi/ipmi_si_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/char/ipmi/ipmi_si_platform.c +1
-2@@ -269,7 +269,7 @@ static int of_ipmi_probe(struct platform_device *pdev) }memset (&io,0 ,sizeof (io)); - io.si_type = (enum si_type ) match->data; + io.si_type = (unsigned long ) match->data; io.addr_source =SI_DEVICETREE ; io.irq_setup = ipmi_std_irq_setup; ---base-commit:
c1a515d3c0270628df8ae5f5118ba859b85464a2
change-id: 20230809-cbl-1902-7532a747b731Best regards,
--
Justin Stitt <[email protected]>