linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pci: ftpci100: fix of_irq_get() error check
@ 2017-07-15 21:43 Sergei Shtylyov
  2017-07-15 21:56 ` Sergei Shtylyov
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Sergei Shtylyov @ 2017-07-15 21:43 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci; +Cc: Linus Walleij, Sergei Shtylyov

of_irq_get() may return a negative error number as well as 0 on failure,
while the driver only checks for 0, blithely continuing with the call to
irq_set_chained_handler_and_data() -- that function expects *unsigned int*
so should probably do nothing when a large IRQ number resulting from a
conversion of a negative error number is passed to it. The driver then
probes successfully while being only partly functional...

Check for 'irq <= 0' instead and propagate the negative error number to
the probe method --  that will allow the deferred probing as well...

Fixes: d3c68e0a7e34 ("PCI: faraday: Add Faraday Technology FTPCI100 PCI Host Bridge driver")
Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

---
 drivers/pci/host/pci-ftpci100.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: pci/drivers/pci/host/pci-ftpci100.c
===================================================================
--- pci.orig/drivers/pci/host/pci-ftpci100.c
+++ pci/drivers/pci/host/pci-ftpci100.c
@@ -350,9 +350,9 @@ static int faraday_pci_setup_cascaded_ir
 
 	/* All PCI IRQs cascade off this one */
 	irq = of_irq_get(intc, 0);
-	if (!irq) {
+	if (irq <= 0) {
 		dev_err(p->dev, "failed to get parent IRQ\n");
-		return -EINVAL;
+		return irq ?: -EINVAL;
 	}
 
 	p->irqdomain = irq_domain_add_linear(intc, 4,

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

* Re: [PATCH] pci: ftpci100: fix of_irq_get() error check
  2017-07-15 21:43 [PATCH] pci: ftpci100: fix of_irq_get() error check Sergei Shtylyov
@ 2017-07-15 21:56 ` Sergei Shtylyov
  2017-07-16 21:17 ` Linus Walleij
  2017-08-02 21:36 ` Bjorn Helgaas
  2 siblings, 0 replies; 8+ messages in thread
From: Sergei Shtylyov @ 2017-07-15 21:56 UTC (permalink / raw)
  To: Bjorn Helgaas, linux-pci; +Cc: Linus Walleij

Sorry, forgot to mention that the patch is against Bjorn Helgaas's pci.git 
repo's master branch.

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

* Re: [PATCH] pci: ftpci100: fix of_irq_get() error check
  2017-07-15 21:43 [PATCH] pci: ftpci100: fix of_irq_get() error check Sergei Shtylyov
  2017-07-15 21:56 ` Sergei Shtylyov
@ 2017-07-16 21:17 ` Linus Walleij
  2017-07-17  9:55   ` Sergei Shtylyov
  2017-08-02 21:36 ` Bjorn Helgaas
  2 siblings, 1 reply; 8+ messages in thread
From: Linus Walleij @ 2017-07-16 21:17 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: Bjorn Helgaas, linux-pci

On Sat, Jul 15, 2017 at 11:43 PM, Sergei Shtylyov
<sergei.shtylyov@cogentembedded.com> wrote:

> of_irq_get() may return a negative error number as well as 0 on failure,
> while the driver only checks for 0, blithely continuing with the call to
> irq_set_chained_handler_and_data() -- that function expects *unsigned int*
> so should probably do nothing when a large IRQ number resulting from a
> conversion of a negative error number is passed to it. The driver then
> probes successfully while being only partly functional...
>
> Check for 'irq <= 0' instead and propagate the negative error number to
> the probe method --  that will allow the deferred probing as well...
>
> Fixes: d3c68e0a7e34 ("PCI: faraday: Add Faraday Technology FTPCI100 PCI Host Bridge driver")
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

Looks correct!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

> -               return -EINVAL;
> +               return irq ?: -EINVAL;

I thought I knew C but I learn something new all the time.
I had no clue one can use the ternary operator like this.

Linus Walleij

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

* Re: [PATCH] pci: ftpci100: fix of_irq_get() error check
  2017-07-16 21:17 ` Linus Walleij
@ 2017-07-17  9:55   ` Sergei Shtylyov
  0 siblings, 0 replies; 8+ messages in thread
From: Sergei Shtylyov @ 2017-07-17  9:55 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Bjorn Helgaas, linux-pci

Hello!

On 7/17/2017 12:17 AM, Linus Walleij wrote:

>> of_irq_get() may return a negative error number as well as 0 on failure,
>> while the driver only checks for 0, blithely continuing with the call to
>> irq_set_chained_handler_and_data() -- that function expects *unsigned int*
>> so should probably do nothing when a large IRQ number resulting from a
>> conversion of a negative error number is passed to it. The driver then
>> probes successfully while being only partly functional...
>>
>> Check for 'irq <= 0' instead and propagate the negative error number to
>> the probe method --  that will allow the deferred probing as well...
>>
>> Fixes: d3c68e0a7e34 ("PCI: faraday: Add Faraday Technology FTPCI100 PCI Host Bridge driver")
>> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> 
> Looks correct!
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

    Thanks!

>> -               return -EINVAL;
>> +               return irq ?: -EINVAL;
> 
> I thought I knew C but I learn something new all the time.
> I had no clue one can use the ternary operator like this.

    It's not a standard C, it's gcc's trickery. :-)

> Linus Walleij

MBR, Sergei

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

* Re: [PATCH] pci: ftpci100: fix of_irq_get() error check
  2017-07-15 21:43 [PATCH] pci: ftpci100: fix of_irq_get() error check Sergei Shtylyov
  2017-07-15 21:56 ` Sergei Shtylyov
  2017-07-16 21:17 ` Linus Walleij
@ 2017-08-02 21:36 ` Bjorn Helgaas
  2017-08-03  9:32   ` Sergei Shtylyov
  2 siblings, 1 reply; 8+ messages in thread
From: Bjorn Helgaas @ 2017-08-02 21:36 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: Bjorn Helgaas, linux-pci, Linus Walleij

On Sun, Jul 16, 2017 at 12:43:10AM +0300, Sergei Shtylyov wrote:
> of_irq_get() may return a negative error number as well as 0 on failure,
> while the driver only checks for 0, blithely continuing with the call to
> irq_set_chained_handler_and_data() -- that function expects *unsigned int*
> so should probably do nothing when a large IRQ number resulting from a
> conversion of a negative error number is passed to it. The driver then
> probes successfully while being only partly functional...
> 
> Check for 'irq <= 0' instead and propagate the negative error number to
> the probe method --  that will allow the deferred probing as well...
> 
> Fixes: d3c68e0a7e34 ("PCI: faraday: Add Faraday Technology FTPCI100 PCI Host Bridge driver")
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

Applied with Linus' reviewed-by to pci/host-faraday for v4.14, thanks!

> ---
>  drivers/pci/host/pci-ftpci100.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> Index: pci/drivers/pci/host/pci-ftpci100.c
> ===================================================================
> --- pci.orig/drivers/pci/host/pci-ftpci100.c
> +++ pci/drivers/pci/host/pci-ftpci100.c
> @@ -350,9 +350,9 @@ static int faraday_pci_setup_cascaded_ir
>  
>  	/* All PCI IRQs cascade off this one */
>  	irq = of_irq_get(intc, 0);
> -	if (!irq) {
> +	if (irq <= 0) {
>  		dev_err(p->dev, "failed to get parent IRQ\n");
> -		return -EINVAL;
> +		return irq ?: -EINVAL;
>  	}
>  
>  	p->irqdomain = irq_domain_add_linear(intc, 4,
> 

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

* Re: [PATCH] pci: ftpci100: fix of_irq_get() error check
  2017-08-02 21:36 ` Bjorn Helgaas
@ 2017-08-03  9:32   ` Sergei Shtylyov
  2017-08-03 16:15     ` Bjorn Helgaas
  0 siblings, 1 reply; 8+ messages in thread
From: Sergei Shtylyov @ 2017-08-03  9:32 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: Bjorn Helgaas, linux-pci, Linus Walleij

Hello!

On 8/3/2017 12:36 AM, Bjorn Helgaas wrote:

>> of_irq_get() may return a negative error number as well as 0 on failure,
>> while the driver only checks for 0, blithely continuing with the call to
>> irq_set_chained_handler_and_data() -- that function expects *unsigned int*
>> so should probably do nothing when a large IRQ number resulting from a
>> conversion of a negative error number is passed to it. The driver then
>> probes successfully while being only partly functional...
>>
>> Check for 'irq <= 0' instead and propagate the negative error number to
>> the probe method --  that will allow the deferred probing as well...
>>
>> Fixes: d3c68e0a7e34 ("PCI: faraday: Add Faraday Technology FTPCI100 PCI Host Bridge driver")
>> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> 
> Applied with Linus' reviewed-by to pci/host-faraday for v4.14, thanks!

    Thanks! But why only to 4.14?

[...]

MBR, Sergei

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

* Re: [PATCH] pci: ftpci100: fix of_irq_get() error check
  2017-08-03  9:32   ` Sergei Shtylyov
@ 2017-08-03 16:15     ` Bjorn Helgaas
  2017-08-03 16:23       ` Sergei Shtylyov
  0 siblings, 1 reply; 8+ messages in thread
From: Bjorn Helgaas @ 2017-08-03 16:15 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: Bjorn Helgaas, linux-pci, Linus Walleij

On Thu, Aug 03, 2017 at 12:32:29PM +0300, Sergei Shtylyov wrote:
> Hello!
> 
> On 8/3/2017 12:36 AM, Bjorn Helgaas wrote:
> 
> >>of_irq_get() may return a negative error number as well as 0 on failure,
> >>while the driver only checks for 0, blithely continuing with the call to
> >>irq_set_chained_handler_and_data() -- that function expects *unsigned int*
> >>so should probably do nothing when a large IRQ number resulting from a
> >>conversion of a negative error number is passed to it. The driver then
> >>probes successfully while being only partly functional...
> >>
> >>Check for 'irq <= 0' instead and propagate the negative error number to
> >>the probe method --  that will allow the deferred probing as well...
> >>
> >>Fixes: d3c68e0a7e34 ("PCI: faraday: Add Faraday Technology FTPCI100 PCI Host Bridge driver")
> >>Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> >
> >Applied with Linus' reviewed-by to pci/host-faraday for v4.14, thanks!
> 
>    Thanks! But why only to 4.14?

Standard practice.  We're currently in the v4.13 cycle, and the merge
window is closed, so the only changes we add for v4.13 are (1) fixes
for something we merged during the v4.13 merge window, or (2) critical
fixes that can't wait for v4.14.

If we want something backported to stable kernels, we can add a tag
for that.  That might apply in this case?  Your patch is a fix for
d3c68e0a7e34 ("PCI: faraday: Add Faraday Technology FTPCI100 PCI Host
Bridge driver"), which appeared in v4.12, so we might want to tag it
for any v4.12 or v4.13 stable kernels.

Bjorn

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

* Re: [PATCH] pci: ftpci100: fix of_irq_get() error check
  2017-08-03 16:15     ` Bjorn Helgaas
@ 2017-08-03 16:23       ` Sergei Shtylyov
  0 siblings, 0 replies; 8+ messages in thread
From: Sergei Shtylyov @ 2017-08-03 16:23 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: Bjorn Helgaas, linux-pci, Linus Walleij

On 08/03/2017 07:15 PM, Bjorn Helgaas wrote:

>>>> of_irq_get() may return a negative error number as well as 0 on failure,
>>>> while the driver only checks for 0, blithely continuing with the call to
>>>> irq_set_chained_handler_and_data() -- that function expects *unsigned int*
>>>> so should probably do nothing when a large IRQ number resulting from a
>>>> conversion of a negative error number is passed to it. The driver then
>>>> probes successfully while being only partly functional...
>>>>
>>>> Check for 'irq <= 0' instead and propagate the negative error number to
>>>> the probe method --  that will allow the deferred probing as well...
>>>>
>>>> Fixes: d3c68e0a7e34 ("PCI: faraday: Add Faraday Technology FTPCI100 PCI Host Bridge driver")
>>>> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
>>>
>>> Applied with Linus' reviewed-by to pci/host-faraday for v4.14, thanks!
>>
>>     Thanks! But why only to 4.14?
> 
> Standard practice.  We're currently in the v4.13 cycle, and the merge
> window is closed, so the only changes we add for v4.13 are (1) fixes
> for something we merged during the v4.13 merge window, or (2) critical
> fixes that can't wait for v4.14.

    OK, I thought the original Linus' commit was a bit more recent, like 4.13...

> If we want something backported to stable kernels, we can add a tag
> for that.  That might apply in this case?  Your patch is a fix for
> d3c68e0a7e34 ("PCI: faraday: Add Faraday Technology FTPCI100 PCI Host
> Bridge driver"), which appeared in v4.12,

    If not in 4.11...

> so we might want to tag it for any v4.12 or v4.13 stable kernels.

    I think the -stable people look at the Fixes: tag now...

> Bjorn

MBR, Sergei

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

end of thread, other threads:[~2017-08-03 16:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-15 21:43 [PATCH] pci: ftpci100: fix of_irq_get() error check Sergei Shtylyov
2017-07-15 21:56 ` Sergei Shtylyov
2017-07-16 21:17 ` Linus Walleij
2017-07-17  9:55   ` Sergei Shtylyov
2017-08-02 21:36 ` Bjorn Helgaas
2017-08-03  9:32   ` Sergei Shtylyov
2017-08-03 16:15     ` Bjorn Helgaas
2017-08-03 16:23       ` Sergei Shtylyov

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