linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] soc: renesas: rmobile-sysc: fix -Wvoid-pointer-to-enum-cast warning
@ 2023-08-14 22:11 Justin Stitt
  2023-08-30  8:24 ` Geert Uytterhoeven
  0 siblings, 1 reply; 6+ messages in thread
From: Justin Stitt @ 2023-08-14 22:11 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Nathan Chancellor,
	Nick Desaulniers, Tom Rix
  Cc: linux-renesas-soc, linux-kernel, llvm, Justin Stitt

When building with clang 18 I see the following warning:
|      drivers/soc/renesas/rmobile-sysc.c:193:22: warning: cast to smaller integer
|               type 'enum pd_types' from 'const void *' [-Wvoid-pointer-to-enum-cast]
|        193 |                 add_special_pd(np, (enum pd_types)id->data);

This is due to the fact that `id->data` is a void* and `enum pd_types`
has the size of an integer. This cast from pointer-width to int-width
causes truncation and possible data loss. Instead, cast to `uintptr_t`
which has the same width as void*.

Link: https://github.com/ClangBuiltLinux/linux/issues/1910
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Note: It should be noted that there is likely no data loss occurring in
this case since the enum only has a few fields. The narrowing cast from
pointer to int will not lose any data.
---
 drivers/soc/renesas/rmobile-sysc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/soc/renesas/rmobile-sysc.c b/drivers/soc/renesas/rmobile-sysc.c
index 912daadaa10d..0b77f37787d5 100644
--- a/drivers/soc/renesas/rmobile-sysc.c
+++ b/drivers/soc/renesas/rmobile-sysc.c
@@ -190,7 +190,7 @@ static void __init get_special_pds(void)
 
 	/* PM domains containing other special devices */
 	for_each_matching_node_and_match(np, special_ids, &id)
-		add_special_pd(np, (enum pd_types)id->data);
+		add_special_pd(np, (uintptr_t)id->data);
 }
 
 static void __init put_special_pds(void)

---
base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
change-id: 20230814-void-drivers-soc-renesas-rmobile-sysc-98150a2571cc

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


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

* Re: [PATCH] soc: renesas: rmobile-sysc: fix -Wvoid-pointer-to-enum-cast warning
  2023-08-14 22:11 [PATCH] soc: renesas: rmobile-sysc: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
@ 2023-08-30  8:24 ` Geert Uytterhoeven
  2023-09-18  9:20   ` Geert Uytterhoeven
  0 siblings, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2023-08-30  8:24 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Magnus Damm, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-renesas-soc, linux-kernel, llvm

Hi Justin,

On Tue, Aug 15, 2023 at 12:11 AM Justin Stitt <justinstitt@google.com> wrote:
> When building with clang 18 I see the following warning:
> |      drivers/soc/renesas/rmobile-sysc.c:193:22: warning: cast to smaller integer
> |               type 'enum pd_types' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> |        193 |                 add_special_pd(np, (enum pd_types)id->data);
>
> This is due to the fact that `id->data` is a void* and `enum pd_types`
> has the size of an integer. This cast from pointer-width to int-width
> causes truncation and possible data loss. Instead, cast to `uintptr_t`
> which has the same width as void*.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> Reported-by: Nathan Chancellor <nathan@kernel.org>

scripts/checkpatch.pl:

    WARNING: Reported-by: should be immediately followed by Closes:
with a URL to the report

Hence changing the Link: tag to a Closes: tag.

> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
> Note: It should be noted that there is likely no data loss occurring in
> this case since the enum only has a few fields. The narrowing cast from
> pointer to int will not lose any data.

Indeed, the theoretical narrowing could only happen on a 64-bit
platform, while this driver is only used on arm32.

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
i.e. will queue in renesas-devel for v6.7.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] soc: renesas: rmobile-sysc: fix -Wvoid-pointer-to-enum-cast warning
  2023-08-30  8:24 ` Geert Uytterhoeven
@ 2023-09-18  9:20   ` Geert Uytterhoeven
  2023-09-26 11:22     ` Ulf Hansson
  0 siblings, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2023-09-18  9:20 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Justin Stitt, Magnus Damm, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-renesas-soc, linux-kernel, llvm, Linux PM list

Hi Ulf,

On Wed, Aug 30, 2023 at 10:24 AM Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> On Tue, Aug 15, 2023 at 12:11 AM Justin Stitt <justinstitt@google.com> wrote:
> > When building with clang 18 I see the following warning:
> > |      drivers/soc/renesas/rmobile-sysc.c:193:22: warning: cast to smaller integer
> > |               type 'enum pd_types' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> > |        193 |                 add_special_pd(np, (enum pd_types)id->data);
> >
> > This is due to the fact that `id->data` is a void* and `enum pd_types`
> > has the size of an integer. This cast from pointer-width to int-width
> > causes truncation and possible data loss. Instead, cast to `uintptr_t`
> > which has the same width as void*.
> >
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> > Reported-by: Nathan Chancellor <nathan@kernel.org>
>
> scripts/checkpatch.pl:
>
>     WARNING: Reported-by: should be immediately followed by Closes:
> with a URL to the report
>
> Hence changing the Link: tag to a Closes: tag.
>
> > Signed-off-by: Justin Stitt <justinstitt@google.com>
> > ---
> > Note: It should be noted that there is likely no data loss occurring in
> > this case since the enum only has a few fields. The narrowing cast from
> > pointer to int will not lose any data.
>
> Indeed, the theoretical narrowing could only happen on a 64-bit
> platform, while this driver is only used on arm32.
>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> i.e. will queue in renesas-devel for v6.7.

As the Generic PM Domain providers were moved to drivers/pmdomain/
in v6.6-rc2, and now have their own maintainer, I have moved this
commit from renesas-drivers-for-v6.7 to renesas-pmdomain-for-v6.7[1],
with s/soc/pmdomain/ in the oneline-summary.

Ulf: if you prefer, you can still take this patch directly.
Else I will send a PR after rc3 and/or rc5, like I do with my other
renesas-<foo>-for-<version> branches.
Thanks!

[1] https://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git/log/?h=renesas-pmdomain-for-v6.7

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] soc: renesas: rmobile-sysc: fix -Wvoid-pointer-to-enum-cast warning
  2023-09-18  9:20   ` Geert Uytterhoeven
@ 2023-09-26 11:22     ` Ulf Hansson
  2023-09-27  9:28       ` Geert Uytterhoeven
  0 siblings, 1 reply; 6+ messages in thread
From: Ulf Hansson @ 2023-09-26 11:22 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Justin Stitt, Magnus Damm, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-renesas-soc, linux-kernel, llvm, Linux PM list

On Mon, 18 Sept 2023 at 11:21, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Ulf,
>
> On Wed, Aug 30, 2023 at 10:24 AM Geert Uytterhoeven
> <geert@linux-m68k.org> wrote:
> > On Tue, Aug 15, 2023 at 12:11 AM Justin Stitt <justinstitt@google.com> wrote:
> > > When building with clang 18 I see the following warning:
> > > |      drivers/soc/renesas/rmobile-sysc.c:193:22: warning: cast to smaller integer
> > > |               type 'enum pd_types' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> > > |        193 |                 add_special_pd(np, (enum pd_types)id->data);
> > >
> > > This is due to the fact that `id->data` is a void* and `enum pd_types`
> > > has the size of an integer. This cast from pointer-width to int-width
> > > causes truncation and possible data loss. Instead, cast to `uintptr_t`
> > > which has the same width as void*.
> > >
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> > > Reported-by: Nathan Chancellor <nathan@kernel.org>
> >
> > scripts/checkpatch.pl:
> >
> >     WARNING: Reported-by: should be immediately followed by Closes:
> > with a URL to the report
> >
> > Hence changing the Link: tag to a Closes: tag.
> >
> > > Signed-off-by: Justin Stitt <justinstitt@google.com>
> > > ---
> > > Note: It should be noted that there is likely no data loss occurring in
> > > this case since the enum only has a few fields. The narrowing cast from
> > > pointer to int will not lose any data.
> >
> > Indeed, the theoretical narrowing could only happen on a 64-bit
> > platform, while this driver is only used on arm32.
> >
> > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > i.e. will queue in renesas-devel for v6.7.
>
> As the Generic PM Domain providers were moved to drivers/pmdomain/
> in v6.6-rc2, and now have their own maintainer, I have moved this
> commit from renesas-drivers-for-v6.7 to renesas-pmdomain-for-v6.7[1],
> with s/soc/pmdomain/ in the oneline-summary.
>
> Ulf: if you prefer, you can still take this patch directly.
> Else I will send a PR after rc3 and/or rc5, like I do with my other
> renesas-<foo>-for-<version> branches.
> Thanks!

Apologize for the delay, been traveling lately. Anyway, I can
certainly pick up the patch and carry it for v6.7. Just let me know,
if/when you have dropped the patch from your tree.

[...]

Kind regards
Uffe

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

* Re: [PATCH] soc: renesas: rmobile-sysc: fix -Wvoid-pointer-to-enum-cast warning
  2023-09-26 11:22     ` Ulf Hansson
@ 2023-09-27  9:28       ` Geert Uytterhoeven
  2023-09-27 11:14         ` Ulf Hansson
  0 siblings, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2023-09-27  9:28 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Justin Stitt, Magnus Damm, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, linux-renesas-soc, linux-kernel, llvm, Linux PM list

Hi Ulf,

On Tue, Sep 26, 2023 at 1:22 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
> On Mon, 18 Sept 2023 at 11:21, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > On Wed, Aug 30, 2023 at 10:24 AM Geert Uytterhoeven
> > <geert@linux-m68k.org> wrote:
> > > On Tue, Aug 15, 2023 at 12:11 AM Justin Stitt <justinstitt@google.com> wrote:
> > > > When building with clang 18 I see the following warning:
> > > > |      drivers/soc/renesas/rmobile-sysc.c:193:22: warning: cast to smaller integer
> > > > |               type 'enum pd_types' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> > > > |        193 |                 add_special_pd(np, (enum pd_types)id->data);
> > > >
> > > > This is due to the fact that `id->data` is a void* and `enum pd_types`
> > > > has the size of an integer. This cast from pointer-width to int-width
> > > > causes truncation and possible data loss. Instead, cast to `uintptr_t`
> > > > which has the same width as void*.
> > > >
> > > > Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> > > > Reported-by: Nathan Chancellor <nathan@kernel.org>
> > >
> > > scripts/checkpatch.pl:
> > >
> > >     WARNING: Reported-by: should be immediately followed by Closes:
> > > with a URL to the report
> > >
> > > Hence changing the Link: tag to a Closes: tag.
> > >
> > > > Signed-off-by: Justin Stitt <justinstitt@google.com>
> > > > ---
> > > > Note: It should be noted that there is likely no data loss occurring in
> > > > this case since the enum only has a few fields. The narrowing cast from
> > > > pointer to int will not lose any data.
> > >
> > > Indeed, the theoretical narrowing could only happen on a 64-bit
> > > platform, while this driver is only used on arm32.
> > >
> > > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > > i.e. will queue in renesas-devel for v6.7.
> >
> > As the Generic PM Domain providers were moved to drivers/pmdomain/
> > in v6.6-rc2, and now have their own maintainer, I have moved this
> > commit from renesas-drivers-for-v6.7 to renesas-pmdomain-for-v6.7[1],
> > with s/soc/pmdomain/ in the oneline-summary.
> >
> > Ulf: if you prefer, you can still take this patch directly.
> > Else I will send a PR after rc3 and/or rc5, like I do with my other
> > renesas-<foo>-for-<version> branches.
> > Thanks!
>
> Apologize for the delay, been traveling lately. Anyway, I can
> certainly pick up the patch and carry it for v6.7. Just let me know,
> if/when you have dropped the patch from your tree.

Thanks, dropped.

P.S. And now I notice it was never part of linux-next, due to an
     oversight in my scripting. Fixed that, too ;-)

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] soc: renesas: rmobile-sysc: fix -Wvoid-pointer-to-enum-cast warning
  2023-09-27  9:28       ` Geert Uytterhoeven
@ 2023-09-27 11:14         ` Ulf Hansson
  0 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2023-09-27 11:14 UTC (permalink / raw)
  To: Justin Stitt, Geert Uytterhoeven
  Cc: Magnus Damm, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	linux-renesas-soc, linux-kernel, llvm, Linux PM list

On Wed, 27 Sept 2023 at 11:28, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Ulf,
>
> On Tue, Sep 26, 2023 at 1:22 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > On Mon, 18 Sept 2023 at 11:21, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > On Wed, Aug 30, 2023 at 10:24 AM Geert Uytterhoeven
> > > <geert@linux-m68k.org> wrote:
> > > > On Tue, Aug 15, 2023 at 12:11 AM Justin Stitt <justinstitt@google.com> wrote:
> > > > > When building with clang 18 I see the following warning:
> > > > > |      drivers/soc/renesas/rmobile-sysc.c:193:22: warning: cast to smaller integer
> > > > > |               type 'enum pd_types' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> > > > > |        193 |                 add_special_pd(np, (enum pd_types)id->data);
> > > > >
> > > > > This is due to the fact that `id->data` is a void* and `enum pd_types`
> > > > > has the size of an integer. This cast from pointer-width to int-width
> > > > > causes truncation and possible data loss. Instead, cast to `uintptr_t`
> > > > > which has the same width as void*.
> > > > >
> > > > > Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> > > > > Reported-by: Nathan Chancellor <nathan@kernel.org>
> > > >
> > > > scripts/checkpatch.pl:
> > > >
> > > >     WARNING: Reported-by: should be immediately followed by Closes:
> > > > with a URL to the report
> > > >
> > > > Hence changing the Link: tag to a Closes: tag.
> > > >
> > > > > Signed-off-by: Justin Stitt <justinstitt@google.com>
> > > > > ---
> > > > > Note: It should be noted that there is likely no data loss occurring in
> > > > > this case since the enum only has a few fields. The narrowing cast from
> > > > > pointer to int will not lose any data.
> > > >
> > > > Indeed, the theoretical narrowing could only happen on a 64-bit
> > > > platform, while this driver is only used on arm32.
> > > >
> > > > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > > > i.e. will queue in renesas-devel for v6.7.
> > >
> > > As the Generic PM Domain providers were moved to drivers/pmdomain/
> > > in v6.6-rc2, and now have their own maintainer, I have moved this
> > > commit from renesas-drivers-for-v6.7 to renesas-pmdomain-for-v6.7[1],
> > > with s/soc/pmdomain/ in the oneline-summary.
> > >
> > > Ulf: if you prefer, you can still take this patch directly.
> > > Else I will send a PR after rc3 and/or rc5, like I do with my other
> > > renesas-<foo>-for-<version> branches.
> > > Thanks!
> >
> > Apologize for the delay, been traveling lately. Anyway, I can
> > certainly pick up the patch and carry it for v6.7. Just let me know,
> > if/when you have dropped the patch from your tree.
>
> Thanks, dropped.

Applied for next, thanks!

[...]

Kind regards
Uffe

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

end of thread, other threads:[~2023-09-27 11:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-14 22:11 [PATCH] soc: renesas: rmobile-sysc: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
2023-08-30  8:24 ` Geert Uytterhoeven
2023-09-18  9:20   ` Geert Uytterhoeven
2023-09-26 11:22     ` Ulf Hansson
2023-09-27  9:28       ` Geert Uytterhoeven
2023-09-27 11:14         ` Ulf Hansson

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