From: David Miller <davem@davemloft.net>
To: u.kleine-koenig@pengutronix.de
Cc: f.fainelli@gmail.com, netdev@vger.kernel.org,
linus.walleij@linaro.org, acourbot@nvidia.com
Subject: Re: [PATCH] net: phy: at803x: simplify using devm_gpiod_get_optional and its 4th argument
Date: Tue, 31 Mar 2015 12:57:54 -0400 (EDT) [thread overview]
Message-ID: <20150331.125754.1434513759096073981.davem@davemloft.net> (raw)
In-Reply-To: <1427484302-17075-1-git-send-email-u.kleine-koenig@pengutronix.de>
From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date: Fri, 27 Mar 2015 20:25:02 +0100
> @@ -197,15 +197,12 @@ static int at803x_probe(struct phy_device *phydev)
> if (!priv)
> return -ENOMEM;
>
> - priv->gpiod_reset = devm_gpiod_get(dev, "reset");
> - if (IS_ERR(priv->gpiod_reset))
> - priv->gpiod_reset = NULL;
> - else
> - gpiod_direction_output(priv->gpiod_reset, 1);
> + priv->gpiod_reset = devm_gpiod_get_optional(dev, "reset",
> + GPIOD_OUT_HIGH);
>
> phydev->priv = priv;
>
> - return 0;
> + return IS_ERR(priv->gpiod_reset);
> }
>
> static int at803x_config_init(struct phy_device *phydev)
This isn't right.
The current code is necessary, don't change it.
Your "simplification" adds three new bugs:
1) It potentially leaves an error pointer in priv->gpiod_reset
and I explicitly tell people to NEVER do this as it tests as
non-NULL by cleanup code and therefore might be mistakenly
used.
2) It returns the wrong error. IS_ERR() is either true or
false, but if you wanted to do this right you would
return PTR_ERR() if IS_ERR() were true or zero.
3) Clearly this code intended to continue trying and succeed
the probe even if getting "reset" failed, your changes
no longer do this.
I really hate changes like this, don't try to be too cute unless
you fully understand the full repurcussions and the reasons why
someone did things one way or another.
Leaving error pointers live in datastructures is never to be done, and
if I see patches adding code doing it I will reject it on the spot.
next prev parent reply other threads:[~2015-03-31 16:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-27 19:25 [PATCH] net: phy: at803x: simplify using devm_gpiod_get_optional and its 4th argument Uwe Kleine-König
2015-03-28 4:52 ` Alexandre Courbot
2015-03-31 16:57 ` David Miller [this message]
2015-03-31 17:53 ` Uwe Kleine-König
2015-03-31 18:07 ` 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=20150331.125754.1434513759096073981.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=acourbot@nvidia.com \
--cc=f.fainelli@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=netdev@vger.kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.