* [PATCH] leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning
@ 2023-08-16 19:37 Justin Stitt
2023-08-18 16:01 ` Lee Jones
2023-09-19 14:55 ` (subset) " Lee Jones
0 siblings, 2 replies; 5+ messages in thread
From: Justin Stitt @ 2023-08-16 19:37 UTC (permalink / raw)
To: Pavel Machek, Lee Jones, Nathan Chancellor, Nick Desaulniers,
Tom Rix
Cc: linux-leds, linux-kernel, llvm, Justin Stitt
When building with clang 18 I see the following warning:
| drivers/leds/leds-pca955x.c:487:15: warning: cast to smaller integer
| type 'enum pca955x_type' from 'const void *' [-Wvoid-pointer-to-enum-cast]
| 487 | chip_type = (enum pca955x_type)md;
This is due to the fact that `md` is a void* while `enum pca995x_type` has the
size of an int.
Add uintptr_t cast to silence clang warning while also keeping enum cast
for readability and consistency with other `chip_type` assignment just a
few lines below:
| chip_type = (enum pca955x_type)id->driver_data;
Link: https://github.com/ClangBuiltLinux/linux/issues/1910
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning
---
Note: I've opted to keep the initial `enum pca955x_type` cast and just
place the uintptr_t cast first to silence the warning. It seemed weird
to me to see the same variable being assigned to two different casted
values within just a few lines.
---
drivers/leds/leds-pca955x.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
index b10e1ef38db0..1d7fa0cd97bf 100644
--- a/drivers/leds/leds-pca955x.c
+++ b/drivers/leds/leds-pca955x.c
@@ -484,7 +484,7 @@ static int pca955x_probe(struct i2c_client *client)
const void *md = device_get_match_data(&client->dev);
if (md) {
- chip_type = (enum pca955x_type)md;
+ chip_type = (enum pca955x_type)(uintptr_t)md;
} else {
const struct i2c_device_id *id = i2c_match_id(pca955x_id,
client);
---
base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
change-id: 20230816-void-drivers-leds-leds-pca955x-7002cc67a291
Best regards,
--
Justin Stitt <justinstitt@google.com>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning
2023-08-16 19:37 [PATCH] leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
@ 2023-08-18 16:01 ` Lee Jones
2023-08-18 16:06 ` Nathan Chancellor
2023-09-19 14:55 ` (subset) " Lee Jones
1 sibling, 1 reply; 5+ messages in thread
From: Lee Jones @ 2023-08-18 16:01 UTC (permalink / raw)
To: Justin Stitt
Cc: Pavel Machek, Nathan Chancellor, Nick Desaulniers, Tom Rix,
linux-leds, linux-kernel, llvm
On Wed, 16 Aug 2023, Justin Stitt wrote:
> When building with clang 18 I see the following warning:
> | drivers/leds/leds-pca955x.c:487:15: warning: cast to smaller integer
> | type 'enum pca955x_type' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> | 487 | chip_type = (enum pca955x_type)md;
>
> This is due to the fact that `md` is a void* while `enum pca995x_type` has the
> size of an int.
>
> Add uintptr_t cast to silence clang warning while also keeping enum cast
> for readability and consistency with other `chip_type` assignment just a
> few lines below:
> | chip_type = (enum pca955x_type)id->driver_data;
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> Reported-by: Nathan Chancellor <nathan@kernel.org>
A review from Nathan would be good here.
> Signed-off-by: Justin Stitt <justinstitt@google.com>
Also please make checkpatch.pl happy before resending, thanks.
> ---
>
>
> leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning
> ---
> Note: I've opted to keep the initial `enum pca955x_type` cast and just
> place the uintptr_t cast first to silence the warning. It seemed weird
> to me to see the same variable being assigned to two different casted
> values within just a few lines.
> ---
> drivers/leds/leds-pca955x.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
> index b10e1ef38db0..1d7fa0cd97bf 100644
> --- a/drivers/leds/leds-pca955x.c
> +++ b/drivers/leds/leds-pca955x.c
> @@ -484,7 +484,7 @@ static int pca955x_probe(struct i2c_client *client)
> const void *md = device_get_match_data(&client->dev);
>
> if (md) {
> - chip_type = (enum pca955x_type)md;
> + chip_type = (enum pca955x_type)(uintptr_t)md;
> } else {
> const struct i2c_device_id *id = i2c_match_id(pca955x_id,
> client);
>
> ---
> base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
> change-id: 20230816-void-drivers-leds-leds-pca955x-7002cc67a291
>
> Best regards,
> --
> Justin Stitt <justinstitt@google.com>
>
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning
2023-08-18 16:01 ` Lee Jones
@ 2023-08-18 16:06 ` Nathan Chancellor
2023-08-18 17:39 ` Lee Jones
0 siblings, 1 reply; 5+ messages in thread
From: Nathan Chancellor @ 2023-08-18 16:06 UTC (permalink / raw)
To: Lee Jones
Cc: Justin Stitt, Pavel Machek, Nick Desaulniers, Tom Rix, linux-leds,
linux-kernel, llvm
On Fri, Aug 18, 2023 at 05:01:54PM +0100, Lee Jones wrote:
> On Wed, 16 Aug 2023, Justin Stitt wrote:
>
> > When building with clang 18 I see the following warning:
> > | drivers/leds/leds-pca955x.c:487:15: warning: cast to smaller integer
> > | type 'enum pca955x_type' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> > | 487 | chip_type = (enum pca955x_type)md;
> >
> > This is due to the fact that `md` is a void* while `enum pca995x_type` has the
> > size of an int.
> >
> > Add uintptr_t cast to silence clang warning while also keeping enum cast
> > for readability and consistency with other `chip_type` assignment just a
> > few lines below:
> > | chip_type = (enum pca955x_type)id->driver_data;
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> > Reported-by: Nathan Chancellor <nathan@kernel.org>
>
> A review from Nathan would be good here.
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> > Signed-off-by: Justin Stitt <justinstitt@google.com>
>
> Also please make checkpatch.pl happy before resending, thanks.
>
> > ---
> >
> >
> > leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning
> > ---
> > Note: I've opted to keep the initial `enum pca955x_type` cast and just
> > place the uintptr_t cast first to silence the warning. It seemed weird
> > to me to see the same variable being assigned to two different casted
> > values within just a few lines.
> > ---
> > drivers/leds/leds-pca955x.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
> > index b10e1ef38db0..1d7fa0cd97bf 100644
> > --- a/drivers/leds/leds-pca955x.c
> > +++ b/drivers/leds/leds-pca955x.c
> > @@ -484,7 +484,7 @@ static int pca955x_probe(struct i2c_client *client)
> > const void *md = device_get_match_data(&client->dev);
> >
> > if (md) {
> > - chip_type = (enum pca955x_type)md;
> > + chip_type = (enum pca955x_type)(uintptr_t)md;
> > } else {
> > const struct i2c_device_id *id = i2c_match_id(pca955x_id,
> > client);
> >
> > ---
> > base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
> > change-id: 20230816-void-drivers-leds-leds-pca955x-7002cc67a291
> >
> > Best regards,
> > --
> > Justin Stitt <justinstitt@google.com>
> >
>
> --
> Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning
2023-08-18 16:06 ` Nathan Chancellor
@ 2023-08-18 17:39 ` Lee Jones
0 siblings, 0 replies; 5+ messages in thread
From: Lee Jones @ 2023-08-18 17:39 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Justin Stitt, Pavel Machek, Nick Desaulniers, Tom Rix, linux-leds,
linux-kernel, llvm
On Fri, 18 Aug 2023, Nathan Chancellor wrote:
> On Fri, Aug 18, 2023 at 05:01:54PM +0100, Lee Jones wrote:
> > On Wed, 16 Aug 2023, Justin Stitt wrote:
> >
> > > When building with clang 18 I see the following warning:
> > > | drivers/leds/leds-pca955x.c:487:15: warning: cast to smaller integer
> > > | type 'enum pca955x_type' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> > > | 487 | chip_type = (enum pca955x_type)md;
> > >
> > > This is due to the fact that `md` is a void* while `enum pca995x_type` has the
> > > size of an int.
> > >
> > > Add uintptr_t cast to silence clang warning while also keeping enum cast
> > > for readability and consistency with other `chip_type` assignment just a
> > > few lines below:
> > > | chip_type = (enum pca955x_type)id->driver_data;
> > >
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> > > Reported-by: Nathan Chancellor <nathan@kernel.org>
> >
> > A review from Nathan would be good here.
>
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Thank you.
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: (subset) [PATCH] leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning
2023-08-16 19:37 [PATCH] leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
2023-08-18 16:01 ` Lee Jones
@ 2023-09-19 14:55 ` Lee Jones
1 sibling, 0 replies; 5+ messages in thread
From: Lee Jones @ 2023-09-19 14:55 UTC (permalink / raw)
To: Pavel Machek, Lee Jones, Nathan Chancellor, Nick Desaulniers,
Tom Rix, Justin Stitt
Cc: linux-leds, linux-kernel, llvm
On Wed, 16 Aug 2023 19:37:52 +0000, Justin Stitt wrote:
> When building with clang 18 I see the following warning:
> | drivers/leds/leds-pca955x.c:487:15: warning: cast to smaller integer
> | type 'enum pca955x_type' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> | 487 | chip_type = (enum pca955x_type)md;
>
> This is due to the fact that `md` is a void* while `enum pca995x_type` has the
> size of an int.
>
> [...]
Applied, thanks!
[1/1] leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning
commit: 0e2e05099162c089a9b4dac563ae71b4c01a5f8b
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-09-19 14:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-16 19:37 [PATCH] leds: pca955x: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
2023-08-18 16:01 ` Lee Jones
2023-08-18 16:06 ` Nathan Chancellor
2023-08-18 17:39 ` Lee Jones
2023-09-19 14:55 ` (subset) " Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).