linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of/irq: handle irq_of_parse_and_map() errors
@ 2024-08-30 14:21 Ma Ke
  2024-09-03 16:56 ` Christophe Leroy
  2024-09-06 14:36 ` Thomas Gleixner
  0 siblings, 2 replies; 4+ messages in thread
From: Ma Ke @ 2024-08-30 14:21 UTC (permalink / raw)
  To: jochen, andi.shyti, grant.likely, thierry.reding, rob.herring
  Cc: linuxppc-dev, linux-i2c, linux-kernel, Ma Ke, stable

Zero and negative number is not a valid IRQ for in-kernel code and the
irq_of_parse_and_map() function returns zero on error.  So this check for
valid IRQs should only accept values > 0.

Cc: stable@vger.kernel.org
Fixes: f7578496a671 ("of/irq: Use irq_of_parse_and_map()")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 drivers/i2c/busses/i2c-cpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index 4794ec066eb0..41e3c95c0ef7 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -435,7 +435,7 @@ static int cpm_i2c_setup(struct cpm_i2c *cpm)
 	init_waitqueue_head(&cpm->i2c_wait);
 
 	cpm->irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
-	if (!cpm->irq)
+	if (cpm->irq <= 0)
 		return -EINVAL;
 
 	/* Install interrupt handler. */
-- 
2.25.1



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

* Re: [PATCH] of/irq: handle irq_of_parse_and_map() errors
  2024-08-30 14:21 [PATCH] of/irq: handle irq_of_parse_and_map() errors Ma Ke
@ 2024-09-03 16:56 ` Christophe Leroy
  2024-09-03 22:55   ` Andi Shyti
  2024-09-06 14:36 ` Thomas Gleixner
  1 sibling, 1 reply; 4+ messages in thread
From: Christophe Leroy @ 2024-09-03 16:56 UTC (permalink / raw)
  To: Ma Ke, jochen, andi.shyti, grant.likely, thierry.reding,
	rob.herring
  Cc: linuxppc-dev, linux-i2c, linux-kernel, stable



Le 30/08/2024 à 16:21, Ma Ke a écrit :
> Zero and negative number is not a valid IRQ for in-kernel code and the
> irq_of_parse_and_map() function returns zero on error.  So this check for
> valid IRQs should only accept values > 0.

unsigned int irq_of_parse_and_map(struct device_node *node, int index);

I can't see how an 'unsigned int' can be negative.

Christophe

> 
> Cc: stable@vger.kernel.org
> Fixes: f7578496a671 ("of/irq: Use irq_of_parse_and_map()")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
>   drivers/i2c/busses/i2c-cpm.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
> index 4794ec066eb0..41e3c95c0ef7 100644
> --- a/drivers/i2c/busses/i2c-cpm.c
> +++ b/drivers/i2c/busses/i2c-cpm.c
> @@ -435,7 +435,7 @@ static int cpm_i2c_setup(struct cpm_i2c *cpm)
>   	init_waitqueue_head(&cpm->i2c_wait);
>   
>   	cpm->irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
> -	if (!cpm->irq)
> +	if (cpm->irq <= 0)
>   		return -EINVAL;
>   
>   	/* Install interrupt handler. */


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

* Re: [PATCH] of/irq: handle irq_of_parse_and_map() errors
  2024-09-03 16:56 ` Christophe Leroy
@ 2024-09-03 22:55   ` Andi Shyti
  0 siblings, 0 replies; 4+ messages in thread
From: Andi Shyti @ 2024-09-03 22:55 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Ma Ke, jochen, grant.likely, thierry.reding, rob.herring,
	linuxppc-dev, linux-i2c, linux-kernel, stable

On Tue, Sep 03, 2024 at 06:56:41PM GMT, Christophe Leroy wrote:
> Le 30/08/2024 à 16:21, Ma Ke a écrit :
> > Zero and negative number is not a valid IRQ for in-kernel code and the
> > irq_of_parse_and_map() function returns zero on error.  So this check for
> > valid IRQs should only accept values > 0.
> 
> unsigned int irq_of_parse_and_map(struct device_node *node, int index);
> 
> I can't see how an 'unsigned int' can be negative.

hehe... correct... even though looks like we are walking on a
slackline, relying too much that no one in the future, inside
irq_of_parse_and_map() (and various callers), someone will try to
fit an -ENOSOMETHING into the unsigned int.

I wouldn't mind something like this[*] to ensure I can sleep
soundly.

Thanks for the review,
Andi

[*]
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index cea8f6874b1fb..df44a8ffa6843 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -954,6 +954,8 @@ unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec)
 out:
        mutex_unlock(&domain->root->mutex);

+       BUG_ON(virq < 0);
+
        return virq;
 }
 EXPORT_SYMBOL_GPL(irq_create_fwspec_mapping);

> Christophe
> 
> > 
> > Cc: stable@vger.kernel.org
> > Fixes: f7578496a671 ("of/irq: Use irq_of_parse_and_map()")
> > Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> > ---
> >   drivers/i2c/busses/i2c-cpm.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
> > index 4794ec066eb0..41e3c95c0ef7 100644
> > --- a/drivers/i2c/busses/i2c-cpm.c
> > +++ b/drivers/i2c/busses/i2c-cpm.c
> > @@ -435,7 +435,7 @@ static int cpm_i2c_setup(struct cpm_i2c *cpm)
> >   	init_waitqueue_head(&cpm->i2c_wait);
> >   	cpm->irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
> > -	if (!cpm->irq)
> > +	if (cpm->irq <= 0)
> >   		return -EINVAL;
> >   	/* Install interrupt handler. */


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

* Re: [PATCH] of/irq: handle irq_of_parse_and_map() errors
  2024-08-30 14:21 [PATCH] of/irq: handle irq_of_parse_and_map() errors Ma Ke
  2024-09-03 16:56 ` Christophe Leroy
@ 2024-09-06 14:36 ` Thomas Gleixner
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas Gleixner @ 2024-09-06 14:36 UTC (permalink / raw)
  To: Ma Ke, jochen, andi.shyti, grant.likely, thierry.reding,
	rob.herring
  Cc: linuxppc-dev, linux-i2c, linux-kernel, Ma Ke, stable

On Fri, Aug 30 2024 at 22:21, Ma Ke wrote:
> Zero and negative number is not a valid IRQ for in-kernel code and the
> irq_of_parse_and_map() function returns zero on error.  So this check for
> valid IRQs should only accept values > 0.

The subsystem prefix is wrong. This changes drivers/i2c/busses/i2c-cpm.c
and has nothing to do with of/irq. Sure, the problem has been caused
by the commit below, but that's a different thing.

> Cc: stable@vger.kernel.org
> Fixes: f7578496a671 ("of/irq: Use irq_of_parse_and_map()")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
>  drivers/i2c/busses/i2c-cpm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
> index 4794ec066eb0..41e3c95c0ef7 100644
> --- a/drivers/i2c/busses/i2c-cpm.c
> +++ b/drivers/i2c/busses/i2c-cpm.c
> @@ -435,7 +435,7 @@ static int cpm_i2c_setup(struct cpm_i2c *cpm)
>  	init_waitqueue_head(&cpm->i2c_wait);
>  
>  	cpm->irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
> -	if (!cpm->irq)
> +	if (cpm->irq <= 0)
>  		return -EINVAL;

The function _cannot return a negative number:

extern unsigned int irq_of_parse_and_map(struct device_node *node, int index);

So what is this actually fixing?

Thanks,

        tglx


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

end of thread, other threads:[~2024-09-06 14:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-30 14:21 [PATCH] of/irq: handle irq_of_parse_and_map() errors Ma Ke
2024-09-03 16:56 ` Christophe Leroy
2024-09-03 22:55   ` Andi Shyti
2024-09-06 14:36 ` Thomas Gleixner

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