* [PATCH] mtd: nand: atmel: fix of_irq_get() error check
@ 2017-08-05 21:14 Sergei Shtylyov
2017-08-07 3:38 ` Yang, Wenyou
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Sergei Shtylyov @ 2017-08-05 21:14 UTC (permalink / raw)
To: Wenyou Yang, Josh Wu, Boris Brezillon, Richard Weinberger,
David Woodhouse, Brian Norris, Marek Vasut, Cyrille Pitchen,
linux-mtd
Cc: Sergei Shtylyov
[-- Attachment #1: mtd-nand-atmel-fix-of_irq_get-error-check.patch --]
[-- Type: text/plain, Size: 1693 bytes --]
of_irq_get() may return 0 as well as negative error number on failure,
while the driver only checks for the negative values. The driver would
then call devm_request_irq() for IRQ0 in its probe method and never get
a valid interrupt.
Check for 'nc->irq <= 0' instead and return -ENXIO from the driver's probe
iff of_irq_get() returned 0.
Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
---
The patch is against the 'master' branch of the 'linux-mtd.git' repo --
the 'nand/fixes' branch seems too old...
drivers/mtd/nand/atmel/nand-controller.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
Index: linux-mtd/drivers/mtd/nand/atmel/nand-controller.c
===================================================================
--- linux-mtd.orig/drivers/mtd/nand/atmel/nand-controller.c
+++ linux-mtd/drivers/mtd/nand/atmel/nand-controller.c
@@ -2078,11 +2078,11 @@ atmel_hsmc_nand_controller_legacy_init(s
}
nc->irq = of_irq_get(nand_np, 0);
- if (nc->irq < 0) {
- ret = nc->irq;
- if (ret != -EPROBE_DEFER)
+ if (nc->irq <= 0) {
+ if (nc->irq != -EPROBE_DEFER)
dev_err(dev, "Failed to get IRQ number (err = %d)\n",
- ret);
+ nc->irq);
+ ret = nc->irq ?: -ENXIO;
goto out;
}
@@ -2168,11 +2168,11 @@ atmel_hsmc_nand_controller_init(struct a
nc->irq = of_irq_get(np, 0);
of_node_put(np);
- if (nc->irq < 0) {
+ if (nc->irq <= 0) {
if (nc->irq != -EPROBE_DEFER)
dev_err(dev, "Failed to get IRQ number (err = %d)\n",
nc->irq);
- return nc->irq;
+ return nc->irq ?: -ENXIO;
}
np = of_parse_phandle(dev->of_node, "atmel,nfc-io", 0);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mtd: nand: atmel: fix of_irq_get() error check
2017-08-05 21:14 [PATCH] mtd: nand: atmel: fix of_irq_get() error check Sergei Shtylyov
@ 2017-08-07 3:38 ` Yang, Wenyou
2017-08-07 3:50 ` Wenyou.Yang
2017-08-07 3:45 ` Wenyou.Yang
2017-08-10 9:59 ` Boris Brezillon
2 siblings, 1 reply; 7+ messages in thread
From: Yang, Wenyou @ 2017-08-07 3:38 UTC (permalink / raw)
To: Wenyou Yang, Boris Brezillon, Richard Weinberger, David Woodhouse,
Brian Norris, Marek Vasut, Cyrille Pitchen, linux-mtd
tested
On 2017/8/6 5:14, Sergei Shtylyov wrote:
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH] mtd: nand: atmel: fix of_irq_get() error check
2017-08-05 21:14 [PATCH] mtd: nand: atmel: fix of_irq_get() error check Sergei Shtylyov
2017-08-07 3:38 ` Yang, Wenyou
@ 2017-08-07 3:45 ` Wenyou.Yang
2017-08-10 9:59 ` Boris Brezillon
2 siblings, 0 replies; 7+ messages in thread
From: Wenyou.Yang @ 2017-08-07 3:45 UTC (permalink / raw)
To: sergei.shtylyov, rainyfeeling, boris.brezillon, richard, dwmw2,
computersforpeace, marek.vasut, cyrille.pitchen, linux-mtd
> -----Original Message-----
> From: Sergei Shtylyov [mailto:sergei.shtylyov@cogentembedded.com]
> Sent: 2017年8月6日 5:14
> To: Wenyou Yang - A41535 <Wenyou.Yang@microchip.com>; Josh Wu
> <rainyfeeling@outlook.com>; Boris Brezillon <boris.brezillon@free-
> electrons.com>; Richard Weinberger <richard@nod.at>; David Woodhouse
> <dwmw2@infradead.org>; Brian Norris <computersforpeace@gmail.com>; Marek
> Vasut <marek.vasut@gmail.com>; Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>;
> linux-mtd@lists.infradead.org
> Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> Subject: [PATCH] mtd: nand: atmel: fix of_irq_get() error check
>
> of_irq_get() may return 0 as well as negative error number on failure, while the
> driver only checks for the negative values. The driver would then call
> devm_request_irq() for IRQ0 in its probe method and never get a valid interrupt.
>
> Check for 'nc->irq <= 0' instead and return -ENXIO from the driver's probe iff
> of_irq_get() returned 0.
>
> Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
>
Indeed.
Acked-by: Wenyou Yang <Wenyou.yang@microchip.com>
Best Regards,
Wenyou Yang
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH] mtd: nand: atmel: fix of_irq_get() error check
2017-08-07 3:38 ` Yang, Wenyou
@ 2017-08-07 3:50 ` Wenyou.Yang
0 siblings, 0 replies; 7+ messages in thread
From: Wenyou.Yang @ 2017-08-07 3:50 UTC (permalink / raw)
To: boris.brezillon, richard, dwmw2, computersforpeace, marek.vasut,
cyrille.pitchen, linux-mtd
Sorry, noise, please ignore.
> -----Original Message-----
> From: Wenyou Yang - A41535
> Sent: 2017年8月7日 11:39
> To: Wenyou Yang - A41535 <Wenyou.Yang@microchip.com>; Boris Brezillon
> <boris.brezillon@free-electrons.com>; Richard Weinberger <richard@nod.at>;
> David Woodhouse <dwmw2@infradead.org>; Brian Norris
> <computersforpeace@gmail.com>; Marek Vasut <marek.vasut@gmail.com>;
> Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>; linux-mtd@lists.infradead.org
> Subject: Re: [PATCH] mtd: nand: atmel: fix of_irq_get() error check
>
> tested
>
>
> On 2017/8/6 5:14, Sergei Shtylyov wrote:
Best Regards,
Wenyou Yang
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mtd: nand: atmel: fix of_irq_get() error check
2017-08-05 21:14 [PATCH] mtd: nand: atmel: fix of_irq_get() error check Sergei Shtylyov
2017-08-07 3:38 ` Yang, Wenyou
2017-08-07 3:45 ` Wenyou.Yang
@ 2017-08-10 9:59 ` Boris Brezillon
2017-08-10 10:12 ` Sergei Shtylyov
2 siblings, 1 reply; 7+ messages in thread
From: Boris Brezillon @ 2017-08-10 9:59 UTC (permalink / raw)
To: Sergei Shtylyov
Cc: Wenyou Yang, Josh Wu, Richard Weinberger, David Woodhouse,
Brian Norris, Marek Vasut, Cyrille Pitchen, linux-mtd
Le Sun, 06 Aug 2017 00:14:28 +0300,
Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> a écrit :
> of_irq_get() may return 0 as well as negative error number on failure,
> while the driver only checks for the negative values. The driver would
> then call devm_request_irq() for IRQ0 in its probe method and never get
> a valid interrupt.
>
> Check for 'nc->irq <= 0' instead and return -ENXIO from the driver's probe
> iff of_irq_get() returned 0.
>
> Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
>
> ---
> The patch is against the 'master' branch of the 'linux-mtd.git' repo --
> the 'nand/fixes' branch seems too old...
>
> drivers/mtd/nand/atmel/nand-controller.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> Index: linux-mtd/drivers/mtd/nand/atmel/nand-controller.c
> ===================================================================
> --- linux-mtd.orig/drivers/mtd/nand/atmel/nand-controller.c
> +++ linux-mtd/drivers/mtd/nand/atmel/nand-controller.c
> @@ -2078,11 +2078,11 @@ atmel_hsmc_nand_controller_legacy_init(s
> }
>
> nc->irq = of_irq_get(nand_np, 0);
> - if (nc->irq < 0) {
> - ret = nc->irq;
> - if (ret != -EPROBE_DEFER)
> + if (nc->irq <= 0) {
> + if (nc->irq != -EPROBE_DEFER)
> dev_err(dev, "Failed to get IRQ number (err = %d)\n",
> - ret);
> + nc->irq);
nc->irq can be 0 here which doesn't make any sense for an error return
code, so I'd suggest to still use ret and move the 'ret = nc->irq ?:
-ENXIO' line before doing the != -EPROBE_DEFER test.
> + ret = nc->irq ?: -ENXIO;
Why ENXIO and not EINVAL?
> goto out;
> }
>
> @@ -2168,11 +2168,11 @@ atmel_hsmc_nand_controller_init(struct a
>
> nc->irq = of_irq_get(np, 0);
> of_node_put(np);
> - if (nc->irq < 0) {
> + if (nc->irq <= 0) {
> if (nc->irq != -EPROBE_DEFER)
> dev_err(dev, "Failed to get IRQ number (err = %d)\n",
> nc->irq);
> - return nc->irq;
> + return nc->irq ?: -ENXIO;
> }
>
> np = of_parse_phandle(dev->of_node, "atmel,nfc-io", 0);
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mtd: nand: atmel: fix of_irq_get() error check
2017-08-10 9:59 ` Boris Brezillon
@ 2017-08-10 10:12 ` Sergei Shtylyov
2017-08-13 7:55 ` Boris Brezillon
0 siblings, 1 reply; 7+ messages in thread
From: Sergei Shtylyov @ 2017-08-10 10:12 UTC (permalink / raw)
To: Boris Brezillon
Cc: Wenyou Yang, Josh Wu, Richard Weinberger, David Woodhouse,
Brian Norris, Marek Vasut, Cyrille Pitchen, linux-mtd
On 8/10/2017 12:59 PM, Boris Brezillon wrote:
>> of_irq_get() may return 0 as well as negative error number on failure,
>> while the driver only checks for the negative values. The driver would
>> then call devm_request_irq() for IRQ0 in its probe method and never get
>> a valid interrupt.
>>
>> Check for 'nc->irq <= 0' instead and return -ENXIO from the driver's probe
>> iff of_irq_get() returned 0.
>>
>> Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
>> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
>>
>> ---
>> The patch is against the 'master' branch of the 'linux-mtd.git' repo --
>> the 'nand/fixes' branch seems too old...
>>
>> drivers/mtd/nand/atmel/nand-controller.c | 12 ++++++------
>> 1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> Index: linux-mtd/drivers/mtd/nand/atmel/nand-controller.c
>> ===================================================================
>> --- linux-mtd.orig/drivers/mtd/nand/atmel/nand-controller.c
>> +++ linux-mtd/drivers/mtd/nand/atmel/nand-controller.c
>> @@ -2078,11 +2078,11 @@ atmel_hsmc_nand_controller_legacy_init(s
>> }
>>
>> nc->irq = of_irq_get(nand_np, 0);
>> - if (nc->irq < 0) {
>> - ret = nc->irq;
>> - if (ret != -EPROBE_DEFER)
>> + if (nc->irq <= 0) {
>> + if (nc->irq != -EPROBE_DEFER)
>> dev_err(dev, "Failed to get IRQ number (err = %d)\n",
>> - ret);
>> + nc->irq);
>
> nc->irq can be 0 here which doesn't make any sense for an error return
> code, so I'd suggest to still use ret and move the 'ret = nc->irq ?:
> -ENXIO' line before doing the != -EPROBE_DEFER test.
I tried to keep reporting the original of_irq_get() result. Can change it
if you prefer it another way...
>> + ret = nc->irq ?: -ENXIO;
>
> Why ENXIO and not EINVAL?
That's what platform_get_irq() (another of_irq_get() user) returns if it
doesn't find the IRQ resource.
>> goto out;
>> }
>>
[...]
MBR, Sergei
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mtd: nand: atmel: fix of_irq_get() error check
2017-08-10 10:12 ` Sergei Shtylyov
@ 2017-08-13 7:55 ` Boris Brezillon
0 siblings, 0 replies; 7+ messages in thread
From: Boris Brezillon @ 2017-08-13 7:55 UTC (permalink / raw)
To: Sergei Shtylyov
Cc: Wenyou Yang, Josh Wu, Richard Weinberger, David Woodhouse,
Brian Norris, Marek Vasut, Cyrille Pitchen, linux-mtd
Le Thu, 10 Aug 2017 13:12:09 +0300,
Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> a écrit :
> On 8/10/2017 12:59 PM, Boris Brezillon wrote:
>
> >> of_irq_get() may return 0 as well as negative error number on failure,
> >> while the driver only checks for the negative values. The driver would
> >> then call devm_request_irq() for IRQ0 in its probe method and never get
> >> a valid interrupt.
> >>
> >> Check for 'nc->irq <= 0' instead and return -ENXIO from the driver's probe
> >> iff of_irq_get() returned 0.
> >>
> >> Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
> >> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> >>
> >> ---
> >> The patch is against the 'master' branch of the 'linux-mtd.git' repo --
> >> the 'nand/fixes' branch seems too old...
> >>
> >> drivers/mtd/nand/atmel/nand-controller.c | 12 ++++++------
> >> 1 file changed, 6 insertions(+), 6 deletions(-)
> >>
> >> Index: linux-mtd/drivers/mtd/nand/atmel/nand-controller.c
> >> ===================================================================
> >> --- linux-mtd.orig/drivers/mtd/nand/atmel/nand-controller.c
> >> +++ linux-mtd/drivers/mtd/nand/atmel/nand-controller.c
> >> @@ -2078,11 +2078,11 @@ atmel_hsmc_nand_controller_legacy_init(s
> >> }
> >>
> >> nc->irq = of_irq_get(nand_np, 0);
> >> - if (nc->irq < 0) {
> >> - ret = nc->irq;
> >> - if (ret != -EPROBE_DEFER)
> >> + if (nc->irq <= 0) {
> >> + if (nc->irq != -EPROBE_DEFER)
> >> dev_err(dev, "Failed to get IRQ number (err = %d)\n",
> >> - ret);
> >> + nc->irq);
> >
> > nc->irq can be 0 here which doesn't make any sense for an error return
> > code, so I'd suggest to still use ret and move the 'ret = nc->irq ?:
> > -ENXIO' line before doing the != -EPROBE_DEFER test.
>
> I tried to keep reporting the original of_irq_get() result. Can change it
> if you prefer it another way...
Yep, I prefer to have an error core here. No need to send a new
version, I already fixed the patch when applying.
BTW, it's applied to nand/next not nand/fixes because this bug does not
really impact users as long as the 'interrupts' property is correctly
defined in the DT (which AFAICT is the case).
>
> >> + ret = nc->irq ?: -ENXIO;
> >
> > Why ENXIO and not EINVAL?
>
> That's what platform_get_irq() (another of_irq_get() user) returns if it
> doesn't find the IRQ resource.
Okay.
>
> >> goto out;
> >> }
> >>
> [...]
> MBR, Sergei
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-08-13 7:55 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-05 21:14 [PATCH] mtd: nand: atmel: fix of_irq_get() error check Sergei Shtylyov
2017-08-07 3:38 ` Yang, Wenyou
2017-08-07 3:50 ` Wenyou.Yang
2017-08-07 3:45 ` Wenyou.Yang
2017-08-10 9:59 ` Boris Brezillon
2017-08-10 10:12 ` Sergei Shtylyov
2017-08-13 7:55 ` Boris Brezillon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox