All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] irqchip/gic-v3: fix OF_BAD_ADDR error handling
@ 2021-03-23 13:18 Arnd Bergmann
  2021-03-23 22:06 ` Nick Desaulniers
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Arnd Bergmann @ 2021-03-23 13:18 UTC (permalink / raw)
  To: Thomas Gleixner, Marc Zyngier, Nathan Chancellor, Nick Desaulniers
  Cc: Arnd Bergmann, linux-kernel, clang-built-linux

From: Arnd Bergmann <arnd@arndb.de>

When building with extra warnings enabled, clang points out a
mistake in the error handling:

drivers/irqchip/irq-gic-v3-mbi.c:306:21: error: result of comparison of constant 18446744073709551615 with expression of type 'phys_addr_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
                if (mbi_phys_base == OF_BAD_ADDR) {

Truncate the constant to the same type as the variable it gets compared
to, to shut make the check work and void the warning.

Fixes: 505287525c24 ("irqchip/gic-v3: Add support for Message Based Interrupts as an MSI controller")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/irqchip/irq-gic-v3-mbi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-gic-v3-mbi.c b/drivers/irqchip/irq-gic-v3-mbi.c
index 563a9b366294..e81e89a81cb5 100644
--- a/drivers/irqchip/irq-gic-v3-mbi.c
+++ b/drivers/irqchip/irq-gic-v3-mbi.c
@@ -303,7 +303,7 @@ int __init mbi_init(struct fwnode_handle *fwnode, struct irq_domain *parent)
 	reg = of_get_property(np, "mbi-alias", NULL);
 	if (reg) {
 		mbi_phys_base = of_translate_address(np, reg);
-		if (mbi_phys_base == OF_BAD_ADDR) {
+		if (mbi_phys_base == (phys_addr_t)OF_BAD_ADDR) {
 			ret = -ENXIO;
 			goto err_free_mbi;
 		}
-- 
2.29.2


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

* Re: [PATCH] irqchip/gic-v3: fix OF_BAD_ADDR error handling
  2021-03-23 13:18 [PATCH] irqchip/gic-v3: fix OF_BAD_ADDR error handling Arnd Bergmann
@ 2021-03-23 22:06 ` Nick Desaulniers
  2021-03-24 10:14   ` Marc Zyngier
  2021-04-07 12:31 ` Marc Zyngier
  2021-04-07 12:38 ` [irqchip: irq/irqchip-next] irqchip/gic-v3: Fix " irqchip-bot for Arnd Bergmann
  2 siblings, 1 reply; 6+ messages in thread
From: Nick Desaulniers @ 2021-03-23 22:06 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Thomas Gleixner, Marc Zyngier, Nathan Chancellor, Arnd Bergmann,
	LKML, clang-built-linux

On Tue, Mar 23, 2021 at 6:18 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> When building with extra warnings enabled, clang points out a
> mistake in the error handling:
>
> drivers/irqchip/irq-gic-v3-mbi.c:306:21: error: result of comparison of constant 18446744073709551615 with expression of type 'phys_addr_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

Looks like based on CONFIG_PHYS_ADDR_T_64BIT, phys_addr_t can be u64
or u32, but of_translate_address always returns a u64.  This is fine
for the current value of OF_BAD_ADDR, but I think there's a risk of
losing the top 32b of the return value of of_translate_address() here?

>                 if (mbi_phys_base == OF_BAD_ADDR) {
>
> Truncate the constant to the same type as the variable it gets compared
> to, to shut make the check work and void the warning.
>
> Fixes: 505287525c24 ("irqchip/gic-v3: Add support for Message Based Interrupts as an MSI controller")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/irqchip/irq-gic-v3-mbi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/irqchip/irq-gic-v3-mbi.c b/drivers/irqchip/irq-gic-v3-mbi.c
> index 563a9b366294..e81e89a81cb5 100644
> --- a/drivers/irqchip/irq-gic-v3-mbi.c
> +++ b/drivers/irqchip/irq-gic-v3-mbi.c
> @@ -303,7 +303,7 @@ int __init mbi_init(struct fwnode_handle *fwnode, struct irq_domain *parent)
>         reg = of_get_property(np, "mbi-alias", NULL);
>         if (reg) {
>                 mbi_phys_base = of_translate_address(np, reg);
> -               if (mbi_phys_base == OF_BAD_ADDR) {
> +               if (mbi_phys_base == (phys_addr_t)OF_BAD_ADDR) {
>                         ret = -ENXIO;
>                         goto err_free_mbi;
>                 }
> --
> 2.29.2
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] irqchip/gic-v3: fix OF_BAD_ADDR error handling
  2021-03-23 22:06 ` Nick Desaulniers
@ 2021-03-24 10:14   ` Marc Zyngier
  2021-03-24 10:55     ` Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Zyngier @ 2021-03-24 10:14 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Arnd Bergmann, Thomas Gleixner, Nathan Chancellor, Arnd Bergmann,
	LKML, clang-built-linux

On Tue, 23 Mar 2021 22:06:22 +0000,
Nick Desaulniers <ndesaulniers@google.com> wrote:
> 
> On Tue, Mar 23, 2021 at 6:18 AM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > When building with extra warnings enabled, clang points out a
> > mistake in the error handling:
> >
> > drivers/irqchip/irq-gic-v3-mbi.c:306:21: error: result of comparison of constant 18446744073709551615 with expression of type 'phys_addr_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> 
> Looks like based on CONFIG_PHYS_ADDR_T_64BIT, phys_addr_t can be u64
> or u32, but of_translate_address always returns a u64.  This is fine
> for the current value of OF_BAD_ADDR, but I think there's a risk of
> losing the top 32b of the return value of of_translate_address() here?

If the DT describes a 64bit physical address, and that the (32bit)
kernel isn't built to grok these addresses, then I'd say that the
kernel cannot run on this HW, and that we don't need to worry much
about this case.

In general, CONFIG_PHYS_ADDR_T_64BIT must be selected by the arch code
if anything above 32bit can be described in the PA space.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

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

* Re: [PATCH] irqchip/gic-v3: fix OF_BAD_ADDR error handling
  2021-03-24 10:14   ` Marc Zyngier
@ 2021-03-24 10:55     ` Arnd Bergmann
  0 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2021-03-24 10:55 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Nick Desaulniers, Thomas Gleixner, Nathan Chancellor, LKML,
	clang-built-linux

On Wed, Mar 24, 2021 at 11:14 AM Marc Zyngier <maz@kernel.org> wrote:
>
> On Tue, 23 Mar 2021 22:06:22 +0000,
> Nick Desaulniers <ndesaulniers@google.com> wrote:
> >
> > On Tue, Mar 23, 2021 at 6:18 AM Arnd Bergmann <arnd@kernel.org> wrote:
> > >
> > > From: Arnd Bergmann <arnd@arndb.de>
> > >
> > > When building with extra warnings enabled, clang points out a
> > > mistake in the error handling:
> > >
> > > drivers/irqchip/irq-gic-v3-mbi.c:306:21: error: result of comparison of constant 18446744073709551615 with expression of type 'phys_addr_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
> >
> > Looks like based on CONFIG_PHYS_ADDR_T_64BIT, phys_addr_t can be u64
> > or u32, but of_translate_address always returns a u64.  This is fine
> > for the current value of OF_BAD_ADDR, but I think there's a risk of
> > losing the top 32b of the return value of of_translate_address() here?
>
> If the DT describes a 64bit physical address, and that the (32bit)
> kernel isn't built to grok these addresses, then I'd say that the
> kernel cannot run on this HW, and that we don't need to worry much
> about this case.
>
> In general, CONFIG_PHYS_ADDR_T_64BIT must be selected by the arch code
> if anything above 32bit can be described in the PA space.

Right, this generally works fine, the OF_BAD_ADDR is just a little
hard to get right. Fortunately there are very few comparisons to
OF_BAD_ADDR in other drivers, so I don't think we have to do
anything about it. I looked through every other user of this and found
no problems there, either they use 64-bit temporaries, or they correctly
cast the results.

         Arnd

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

* Re: [PATCH] irqchip/gic-v3: fix OF_BAD_ADDR error handling
  2021-03-23 13:18 [PATCH] irqchip/gic-v3: fix OF_BAD_ADDR error handling Arnd Bergmann
  2021-03-23 22:06 ` Nick Desaulniers
@ 2021-04-07 12:31 ` Marc Zyngier
  2021-04-07 12:38 ` [irqchip: irq/irqchip-next] irqchip/gic-v3: Fix " irqchip-bot for Arnd Bergmann
  2 siblings, 0 replies; 6+ messages in thread
From: Marc Zyngier @ 2021-04-07 12:31 UTC (permalink / raw)
  To: Nick Desaulniers, Nathan Chancellor, Thomas Gleixner, Arnd Bergmann
  Cc: Arnd Bergmann, linux-kernel, clang-built-linux

On Tue, 23 Mar 2021 14:18:35 +0100, Arnd Bergmann wrote:
> When building with extra warnings enabled, clang points out a
> mistake in the error handling:
> 
> drivers/irqchip/irq-gic-v3-mbi.c:306:21: error: result of comparison of constant 18446744073709551615 with expression of type 'phys_addr_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
>                 if (mbi_phys_base == OF_BAD_ADDR) {
> 
> Truncate the constant to the same type as the variable it gets compared
> to, to shut make the check work and void the warning.

Applied to irq/irqchip-next, thanks!

[1/1] irqchip/gic-v3: fix OF_BAD_ADDR error handling
      commit: 8e13d96670a4c050d4883e6743a9e9858e5cfe10

Cheers,

	M.
-- 
Without deviation from the norm, progress is not possible.



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

* [irqchip: irq/irqchip-next] irqchip/gic-v3: Fix OF_BAD_ADDR error handling
  2021-03-23 13:18 [PATCH] irqchip/gic-v3: fix OF_BAD_ADDR error handling Arnd Bergmann
  2021-03-23 22:06 ` Nick Desaulniers
  2021-04-07 12:31 ` Marc Zyngier
@ 2021-04-07 12:38 ` irqchip-bot for Arnd Bergmann
  2 siblings, 0 replies; 6+ messages in thread
From: irqchip-bot for Arnd Bergmann @ 2021-04-07 12:38 UTC (permalink / raw)
  To: linux-kernel; +Cc: Arnd Bergmann, Marc Zyngier, tglx

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     8e13d96670a4c050d4883e6743a9e9858e5cfe10
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/8e13d96670a4c050d4883e6743a9e9858e5cfe10
Author:        Arnd Bergmann <arnd@arndb.de>
AuthorDate:    Tue, 23 Mar 2021 14:18:35 +01:00
Committer:     Marc Zyngier <maz@kernel.org>
CommitterDate: Wed, 07 Apr 2021 13:25:52 +01:00

irqchip/gic-v3: Fix OF_BAD_ADDR error handling

When building with extra warnings enabled, clang points out a
mistake in the error handling:

drivers/irqchip/irq-gic-v3-mbi.c:306:21: error: result of comparison of constant 18446744073709551615 with expression of type 'phys_addr_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
                if (mbi_phys_base == OF_BAD_ADDR) {

Truncate the constant to the same type as the variable it gets compared
to, to shut make the check work and void the warning.

Fixes: 505287525c24 ("irqchip/gic-v3: Add support for Message Based Interrupts as an MSI controller")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210323131842.2773094-1-arnd@kernel.org
---
 drivers/irqchip/irq-gic-v3-mbi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-gic-v3-mbi.c b/drivers/irqchip/irq-gic-v3-mbi.c
index 563a9b3..e81e89a 100644
--- a/drivers/irqchip/irq-gic-v3-mbi.c
+++ b/drivers/irqchip/irq-gic-v3-mbi.c
@@ -303,7 +303,7 @@ int __init mbi_init(struct fwnode_handle *fwnode, struct irq_domain *parent)
 	reg = of_get_property(np, "mbi-alias", NULL);
 	if (reg) {
 		mbi_phys_base = of_translate_address(np, reg);
-		if (mbi_phys_base == OF_BAD_ADDR) {
+		if (mbi_phys_base == (phys_addr_t)OF_BAD_ADDR) {
 			ret = -ENXIO;
 			goto err_free_mbi;
 		}

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

end of thread, other threads:[~2021-04-07 12:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 13:18 [PATCH] irqchip/gic-v3: fix OF_BAD_ADDR error handling Arnd Bergmann
2021-03-23 22:06 ` Nick Desaulniers
2021-03-24 10:14   ` Marc Zyngier
2021-03-24 10:55     ` Arnd Bergmann
2021-04-07 12:31 ` Marc Zyngier
2021-04-07 12:38 ` [irqchip: irq/irqchip-next] irqchip/gic-v3: Fix " irqchip-bot for Arnd Bergmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.