From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Cc: Wenyou Yang <wenyou.yang@atmel.com>,
Josh Wu <rainyfeeling@outlook.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
Date: Thu, 10 Aug 2017 11:59:20 +0200 [thread overview]
Message-ID: <20170810115920.7cbb16f2@bbrezillon> (raw)
In-Reply-To: <20170805211436.181653483@cogentembedded.com>
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);
>
next prev parent reply other threads:[~2017-08-10 9:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2017-08-10 10:12 ` Sergei Shtylyov
2017-08-13 7:55 ` Boris Brezillon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170810115920.7cbb16f2@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@wedev4u.fr \
--cc=dwmw2@infradead.org \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=rainyfeeling@outlook.com \
--cc=richard@nod.at \
--cc=sergei.shtylyov@cogentembedded.com \
--cc=wenyou.yang@atmel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox