llvm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: pxa: fix clang -Wvoid-pointer-to-enum-cast warning
@ 2023-08-16 19:48 Justin Stitt
  2023-08-25 22:17 ` Wolfram Sang
  0 siblings, 1 reply; 6+ messages in thread
From: Justin Stitt @ 2023-08-16 19:48 UTC (permalink / raw)
  To: Andi Shyti, Nathan Chancellor, Nick Desaulniers, Tom Rix
  Cc: linux-i2c, linux-kernel, llvm, Justin Stitt

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@kernel.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
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@google.com>


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] i2c: pxa: fix clang -Wvoid-pointer-to-enum-cast warning
  2023-08-16 19:48 [PATCH] i2c: pxa: fix clang -Wvoid-pointer-to-enum-cast warning Justin Stitt
@ 2023-08-25 22:17 ` Wolfram Sang
  2023-08-25 22:49   ` Justin Stitt
  0 siblings, 1 reply; 6+ messages in thread
From: Wolfram Sang @ 2023-08-25 22:17 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Andi Shyti, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-i2c, linux-kernel, llvm

[-- Attachment #1: Type: text/plain, Size: 462 bytes --]


> 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?

On the one hand, I think this is more explicit and, thus, more readable.
On the other hand, we still have the loss of precision, between the
first and the second cast. Which gives it a bit of a "let's hide it
somewhat so the compiler will be happy" feeling?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i2c: pxa: fix clang -Wvoid-pointer-to-enum-cast warning
  2023-08-25 22:17 ` Wolfram Sang
@ 2023-08-25 22:49   ` Justin Stitt
  2023-08-25 22:52     ` Nick Desaulniers
  2023-08-25 22:59     ` Wolfram Sang
  0 siblings, 2 replies; 6+ messages in thread
From: Justin Stitt @ 2023-08-25 22:49 UTC (permalink / raw)
  To: Wolfram Sang, Justin Stitt, Andi Shyti, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, linux-i2c, linux-kernel, llvm

On Fri, Aug 25, 2023 at 3:17 PM Wolfram Sang <wsa@kernel.org> wrote:
>
>
> > 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?
>
> On the one hand, I think this is more explicit and, thus, more readable.
> On the other hand, we still have the loss of precision, between the
> first and the second cast. Which gives it a bit of a "let's hide it
> somewhat so the compiler will be happy" feeling?
>
There was some discussion [1] wherein it was ultimately decided that
this warning should probably be turned off (contrary to what the title
of the GitHub issue says).

The state of these patches [2] is in some sort of limbo until I get a
patch in to disable the warning from W=1 (keep in mind GCC doesn't
even support this specific warning). I want to make the patch but am
seeking some guidance about what exactly is to be done -- I feel a
simply _demotion_ from W=1 to W=2 would suffice as CI robots aren't
testing w/ that AFAIK.

Nick, do you have anything to add here as we had previously discussed
this off-list/IRL.

[1]: https://github.com/ClangBuiltLinux/linux/issues/1910
[2]: https://lore.kernel.org/all/?q=b%3Apointer-to-enum-cast

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i2c: pxa: fix clang -Wvoid-pointer-to-enum-cast warning
  2023-08-25 22:49   ` Justin Stitt
@ 2023-08-25 22:52     ` Nick Desaulniers
  2023-08-25 22:59     ` Wolfram Sang
  1 sibling, 0 replies; 6+ messages in thread
From: Nick Desaulniers @ 2023-08-25 22:52 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Wolfram Sang, Andi Shyti, Nathan Chancellor, Tom Rix, linux-i2c,
	linux-kernel, llvm

On Fri, Aug 25, 2023 at 3:49 PM Justin Stitt <justinstitt@google.com> wrote:
>
> On Fri, Aug 25, 2023 at 3:17 PM Wolfram Sang <wsa@kernel.org> wrote:
> >
> >
> > > 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?
> >
> > On the one hand, I think this is more explicit and, thus, more readable.
> > On the other hand, we still have the loss of precision, between the
> > first and the second cast. Which gives it a bit of a "let's hide it
> > somewhat so the compiler will be happy" feeling?
> >
> There was some discussion [1] wherein it was ultimately decided that
> this warning should probably be turned off (contrary to what the title
> of the GitHub issue says).
>
> The state of these patches [2] is in some sort of limbo until I get a
> patch in to disable the warning from W=1 (keep in mind GCC doesn't
> even support this specific warning). I want to make the patch but am
> seeking some guidance about what exactly is to be done -- I feel a
> simply _demotion_ from W=1 to W=2 would suffice as CI robots aren't
> testing w/ that AFAIK.
>
> Nick, do you have anything to add here as we had previously discussed
> this off-list/IRL.

Mostly that we should make -fsanitize=enum not totally suck (i.e.
actually do anything for C code, then check for bad conversions from
values that aren't valid enumeration values including truncations),
then disable this warning in favor of folks testing with that
sanitizer enabled.

>
> [1]: https://github.com/ClangBuiltLinux/linux/issues/1910
> [2]: https://lore.kernel.org/all/?q=b%3Apointer-to-enum-cast



-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i2c: pxa: fix clang -Wvoid-pointer-to-enum-cast warning
  2023-08-25 22:49   ` Justin Stitt
  2023-08-25 22:52     ` Nick Desaulniers
@ 2023-08-25 22:59     ` Wolfram Sang
  2023-09-03 10:35       ` Andi Shyti
  1 sibling, 1 reply; 6+ messages in thread
From: Wolfram Sang @ 2023-08-25 22:59 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Andi Shyti, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-i2c, linux-kernel, llvm

[-- Attachment #1: Type: text/plain, Size: 436 bytes --]


> There was some discussion [1] wherein it was ultimately decided that
> this warning should probably be turned off (contrary to what the title
> of the GitHub issue says).

I totally agree with your last comment in [1]. So, I also vote for
disabling the warning. Thus, I will reject these patches, but still
thank you for looking into such issues and trying to solve them!

> [1]: https://github.com/ClangBuiltLinux/linux/issues/1910

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] i2c: pxa: fix clang -Wvoid-pointer-to-enum-cast warning
  2023-08-25 22:59     ` Wolfram Sang
@ 2023-09-03 10:35       ` Andi Shyti
  0 siblings, 0 replies; 6+ messages in thread
From: Andi Shyti @ 2023-09-03 10:35 UTC (permalink / raw)
  To: Wolfram Sang, Justin Stitt, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-i2c, linux-kernel, llvm
  Cc: Andy Shevchenko

Hi,

> > There was some discussion [1] wherein it was ultimately decided that
> > this warning should probably be turned off (contrary to what the title
> > of the GitHub issue says).
> 
> I totally agree with your last comment in [1]. So, I also vote for
> disabling the warning. Thus, I will reject these patches, but still
> thank you for looking into such issues and trying to solve them!

yes, unfortunately this is the trend and most of the patches
follow this approach and they are getting merged.

I don't like pointers storing values and this fix whould be
completely taken from another side. In any case, given the trend,
I will not oppose.

Andi

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-03 10:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-16 19:48 [PATCH] i2c: pxa: fix clang -Wvoid-pointer-to-enum-cast warning Justin Stitt
2023-08-25 22:17 ` Wolfram Sang
2023-08-25 22:49   ` Justin Stitt
2023-08-25 22:52     ` Nick Desaulniers
2023-08-25 22:59     ` Wolfram Sang
2023-09-03 10:35       ` Andi Shyti

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).