* [PATCH] ipmi_si: fix -Wvoid-pointer-to-enum-cast warning
@ 2023-08-09 21:05 Justin Stitt
2023-08-11 20:27 ` Corey Minyard
2023-08-15 20:46 ` Corey Minyard
0 siblings, 2 replies; 4+ messages in thread
From: Justin Stitt @ 2023-08-09 21:05 UTC (permalink / raw)
To: Corey Minyard, Nathan Chancellor, Nick Desaulniers, Tom Rix
Cc: openipmi-developer, linux-kernel, llvm, Arnd Bergmann,
kernel test robot, 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_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.
Link: https://github.com/ClangBuiltLinux/linux/issues/1902
Link: https://lore.kernel.org/llvm/202308081000.tTL1ElTr-lkp@intel.com/
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
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(-)
diff --git a/drivers/char/ipmi/ipmi_si_platform.c b/drivers/char/ipmi/ipmi_si_platform.c
index 505cc978c97a..0d509d683c0f 100644
--- a/drivers/char/ipmi/ipmi_si_platform.c
+++ b/drivers/char/ipmi/ipmi_si_platform.c
@@ -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 <justinstitt@google.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ipmi_si: fix -Wvoid-pointer-to-enum-cast warning
2023-08-09 21:05 [PATCH] ipmi_si: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
@ 2023-08-11 20:27 ` Corey Minyard
2023-08-15 11:19 ` David Laight
2023-08-15 20:46 ` Corey Minyard
1 sibling, 1 reply; 4+ messages in thread
From: Corey Minyard @ 2023-08-11 20:27 UTC (permalink / raw)
To: Justin Stitt
Cc: Nathan Chancellor, Nick Desaulniers, Tom Rix, openipmi-developer,
linux-kernel, llvm, Arnd Bergmann, kernel test robot
On Wed, Aug 09, 2023 at 09:05:17PM +0000, Justin Stitt wrote:
> 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.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1902
> Link: https://lore.kernel.org/llvm/202308081000.tTL1ElTr-lkp@intel.com/
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
> 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(-)
>
> diff --git a/drivers/char/ipmi/ipmi_si_platform.c b/drivers/char/ipmi/ipmi_si_platform.c
> index 505cc978c97a..0d509d683c0f 100644
> --- a/drivers/char/ipmi/ipmi_si_platform.c
> +++ b/drivers/char/ipmi/ipmi_si_platform.c
> @@ -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
> 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 <justinstitt@google.com>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] ipmi_si: fix -Wvoid-pointer-to-enum-cast warning
2023-08-11 20:27 ` Corey Minyard
@ 2023-08-15 11:19 ` David Laight
0 siblings, 0 replies; 4+ messages in thread
From: David Laight @ 2023-08-15 11:19 UTC (permalink / raw)
To: 'minyard@acm.org', Justin Stitt
Cc: Nathan Chancellor, Nick Desaulniers, Tom Rix,
openipmi-developer@lists.sourceforge.net,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Arnd Bergmann,
kernel test robot
From: Corey Minyard
> Sent: 11 August 2023 21:27
...
> > 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?
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)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ipmi_si: fix -Wvoid-pointer-to-enum-cast warning
2023-08-09 21:05 [PATCH] ipmi_si: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
2023-08-11 20:27 ` Corey Minyard
@ 2023-08-15 20:46 ` Corey Minyard
1 sibling, 0 replies; 4+ messages in thread
From: Corey Minyard @ 2023-08-15 20:46 UTC (permalink / raw)
To: Justin Stitt
Cc: Nathan Chancellor, Nick Desaulniers, Tom Rix, openipmi-developer,
linux-kernel, llvm, Arnd Bergmann, kernel test robot
On Wed, Aug 09, 2023 at 09:05:17PM +0000, Justin Stitt wrote:
> 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
>
> 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.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1902
> Link: https://lore.kernel.org/llvm/202308081000.tTL1ElTr-lkp@intel.com/
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
> 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(-)
>
> diff --git a/drivers/char/ipmi/ipmi_si_platform.c b/drivers/char/ipmi/ipmi_si_platform.c
> index 505cc978c97a..0d509d683c0f 100644
> --- a/drivers/char/ipmi/ipmi_si_platform.c
> +++ b/drivers/char/ipmi/ipmi_si_platform.c
> @@ -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 <justinstitt@google.com>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-15 20:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-09 21:05 [PATCH] ipmi_si: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
2023-08-11 20:27 ` Corey Minyard
2023-08-15 11:19 ` David Laight
2023-08-15 20:46 ` Corey Minyard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox