netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Phil Reid <preid@electromag.com.au>
Cc: Pan Bian <bianpan2016@163.com>,
	Vivien Didelot <vivien.didelot@savoirfairelinux.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] net: dsa: lan9303: correctly check return value of devm_gpiod_get_optional
Date: Mon, 13 Nov 2017 05:38:15 +0100	[thread overview]
Message-ID: <20171113043815.GB22473@lunn.ch> (raw)
In-Reply-To: <251e5e33-8bbb-d745-63c8-95d7b34d95f0@electromag.com.au>

On Mon, Nov 13, 2017 at 12:08:49PM +0800, Phil Reid wrote:
> On 12/11/2017 23:38, Pan Bian wrote:
> >Function devm_gpiod_get_optional() returns an ERR_PTR on failure. Its
> >return value should not be validated by a NULL check. Instead, use IS_ERR.
> >
> >Signed-off-by: Pan Bian <bianpan2016@163.com>
> >---
> >  drivers/net/dsa/lan9303-core.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c
> >index b471413..6d3fc8f 100644
> >--- a/drivers/net/dsa/lan9303-core.c
> >+++ b/drivers/net/dsa/lan9303-core.c
> >@@ -828,7 +828,7 @@ static void lan9303_probe_reset_gpio(struct lan9303 *chip,
> >  	chip->reset_gpio = devm_gpiod_get_optional(chip->dev, "reset",
> >  						   GPIOD_OUT_LOW);
> >-	if (!chip->reset_gpio) {
> >+	if (IS_ERR(chip->reset_gpio)) {
> >  		dev_dbg(chip->dev, "No reset GPIO defined\n");
> >  		return;
> >  	}
> >
> Should not an error actually report the error and error out (ie fail probe).
> But a null is the optional return and ok. (ie when -ENOENT return from sub gpiod_get call).
> 
> IS_ERR should be a separate condition check I think.

Hi Phil

Yes, you are right. In particular, -EPROBE_DEFFER should be propagated
up and cause the probe to fail and be called later.

Care to submit a patch?

     Andrew

  reply	other threads:[~2017-11-13  4:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-12 15:38 [PATCH] net: dsa: lan9303: correctly check return value of devm_gpiod_get_optional Pan Bian
2017-11-12 18:29 ` Andrew Lunn
2017-11-13  4:08 ` Phil Reid
2017-11-13  4:38   ` Andrew Lunn [this message]
2017-11-14 12:35 ` David Miller

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=20171113043815.GB22473@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=bianpan2016@163.com \
    --cc=f.fainelli@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=preid@electromag.com.au \
    --cc=stable@vger.kernel.org \
    --cc=vivien.didelot@savoirfairelinux.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;
as well as URLs for NNTP newsgroup(s).