netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net: phy: at803x: simplify using devm_gpiod_get_optional and its 4th argument
@ 2015-03-31 20:08 Uwe Kleine-König
  2015-03-31 23:28 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2015-03-31 20:08 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: netdev, Linus Walleij, Alexandre Courbot, kernel

Since 39b2bbe3d715 (gpio: add flags argument to gpiod_get*() functions)
which appeared in v3.17-rc1, the gpiod_get* functions take an additional
parameter that allows to specify direction and initial value for output.
Moreover use devm_gpiod_get_optional instead of ignoring all errors
returned by devm_gpiod_get and simplify accordingly.

The result is more strict error handling which is good.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

with the local variable introduced to not keep an error value in the
driver struct this doesn't have a positive diffstat anymore. I still
think assigning directly to priv->gpiod_reset would fine because having
the priv->gpiod_reset NULL is neither more nor less right that
ERR_PTR(-ESOMETHING).

Note that my motivation for this change is to get all drivers use the
currently optional fourth parameter to stop it being optional which
needs hard to understand cpp trickery.

Best regards
Uwe

 drivers/net/phy/at803x.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index f80e19ac6704..fabf11d32d27 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -192,16 +192,17 @@ static int at803x_probe(struct phy_device *phydev)
 {
 	struct device *dev = &phydev->dev;
 	struct at803x_priv *priv;
+	struct gpio_desc *gpiod_reset;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	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);
+	gpiod_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(gpiod_reset))
+		return PTR_ERR(gpiod_reset);
+
+	priv->gpiod_reset = gpiod_reset;
 
 	phydev->priv = priv;
 
-- 
2.1.4

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

* Re: [PATCH v2] net: phy: at803x: simplify using devm_gpiod_get_optional and its 4th argument
  2015-03-31 20:08 [PATCH v2] net: phy: at803x: simplify using devm_gpiod_get_optional and its 4th argument Uwe Kleine-König
@ 2015-03-31 23:28 ` David Miller
  2015-04-01  7:00   ` Uwe Kleine-König
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2015-03-31 23:28 UTC (permalink / raw)
  To: u.kleine-koenig; +Cc: f.fainelli, netdev, linus.walleij, acourbot, kernel

From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date: Tue, 31 Mar 2015 22:08:45 +0200

> I still think assigning directly to priv->gpiod_reset would fine
> because having the priv->gpiod_reset NULL is neither more nor less
> right that ERR_PTR(-ESOMETHING).

You really want to push my buttons don't you? :-/

What if someone adds a new resource allocation after this thing and
then adds an unwind path where something has to be done to the GPIOD
as part of cleanup?

What does your error pointer cause to happen to an unsuspecting person
creating such a change?

Why isn't this obvious to you as a good coding practice that is
future proof against any changes to this code?

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

* Re: [PATCH v2] net: phy: at803x: simplify using devm_gpiod_get_optional and its 4th argument
  2015-03-31 23:28 ` David Miller
@ 2015-04-01  7:00   ` Uwe Kleine-König
  2015-04-01 16:14     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2015-04-01  7:00 UTC (permalink / raw)
  To: David Miller; +Cc: f.fainelli, netdev, linus.walleij, acourbot, kernel

On Tue, Mar 31, 2015 at 07:28:38PM -0400, David Miller wrote:
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Date: Tue, 31 Mar 2015 22:08:45 +0200
> 
> > I still think assigning directly to priv->gpiod_reset would fine
> > because having the priv->gpiod_reset NULL is neither more nor less
> > right that ERR_PTR(-ESOMETHING).
> 
> You really want to push my buttons don't you? :-/
> 
> What if someone adds a new resource allocation after this thing and
> then adds an unwind path where something has to be done to the GPIOD
> as part of cleanup?
As I assume that v2 still addresses your concerns it would be ok for me
to not fully agree with you about defensive coding style.
What about you?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

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

* Re: [PATCH v2] net: phy: at803x: simplify using devm_gpiod_get_optional and its 4th argument
  2015-04-01  7:00   ` Uwe Kleine-König
@ 2015-04-01 16:14     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2015-04-01 16:14 UTC (permalink / raw)
  To: u.kleine-koenig; +Cc: f.fainelli, netdev, linus.walleij, acourbot, kernel

From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date: Wed, 1 Apr 2015 09:00:01 +0200

> On Tue, Mar 31, 2015 at 07:28:38PM -0400, David Miller wrote:
>> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>> Date: Tue, 31 Mar 2015 22:08:45 +0200
>> 
>> > I still think assigning directly to priv->gpiod_reset would fine
>> > because having the priv->gpiod_reset NULL is neither more nor less
>> > right that ERR_PTR(-ESOMETHING).
>> 
>> You really want to push my buttons don't you? :-/
>> 
>> What if someone adds a new resource allocation after this thing and
>> then adds an unwind path where something has to be done to the GPIOD
>> as part of cleanup?
> As I assume that v2 still addresses your concerns it would be ok for me
> to not fully agree with you about defensive coding style.
> What about you?

The v2 patch is fine.

What isn't fine is that in the future you'll keep submitting patches that
create dangerous situations, and I intend to keep rejecting them until
you stop putting error pointers into dynamically allocated memory.

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

end of thread, other threads:[~2015-04-01 16:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-31 20:08 [PATCH v2] net: phy: at803x: simplify using devm_gpiod_get_optional and its 4th argument Uwe Kleine-König
2015-03-31 23:28 ` David Miller
2015-04-01  7:00   ` Uwe Kleine-König
2015-04-01 16:14     ` David Miller

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