public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Liu Xiang <liu.xiang@zlingsmart.com>
Cc: netdev@vger.kernel.org, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com
Subject: Re: [PATCH v3] net: stmmac: avoid repeated devm_gpiod_get_optional in mdio
Date: Mon, 27 Apr 2026 14:54:44 +0200	[thread overview]
Message-ID: <20472367-4e8f-457e-a87d-4c3ed8c2cad1@lunn.ch> (raw)
In-Reply-To: <20260427075032.10442-1-liu.xiang@zlingsmart.com>

On Mon, Apr 27, 2026 at 03:50:32PM +0800, Liu Xiang wrote:
> During system resume, stmmac_resume() calls stmmac_mdio_reset().
> This results in repeated calls to devm_gpiod_get_optional() for the same
> GPIO. The second invocation returns an error since the GPIO descriptor has
> already been obtained.
> 
> Suggested-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Liu Xiang <liu.xiang@zlingsmart.com>

Should this have a Fixes: tag?


>  #ifdef CONFIG_OF
>  	if (priv->device->of_node) {
> -		struct gpio_desc *reset_gpio;
> -		u32 delays[3] = { 0, 0, 0 };
> +		if (priv->reset_gpio) {
> +			u32 delays[3] = { 0, 0, 0 };
>  
> -		reset_gpio = devm_gpiod_get_optional(priv->device,
> -						     "snps,reset",
> -						     GPIOD_OUT_LOW);
> -		if (IS_ERR(reset_gpio))
> -			return PTR_ERR(reset_gpio);
> +			device_property_read_u32_array(priv->device,
> +						       "snps,reset-delays-us",
> +						       delays,
> +						       ARRAY_SIZE(delays));
>  
> -		device_property_read_u32_array(priv->device,
> -					       "snps,reset-delays-us",
> -					       delays, ARRAY_SIZE(delays));
> +			gpiod_set_value_cansleep(priv->reset_gpio, 0);
> +			if (delays[0])
> +				msleep(DIV_ROUND_UP(delays[0], 1000));
>  
> -		if (delays[0])
> -			msleep(DIV_ROUND_UP(delays[0], 1000));
> +			gpiod_set_value_cansleep(priv->reset_gpio, 1);
> +			if (delays[1])
> +				msleep(DIV_ROUND_UP(delays[1], 1000));
>  
> -		gpiod_set_value_cansleep(reset_gpio, 1);
> -		if (delays[1])
> -			msleep(DIV_ROUND_UP(delays[1], 1000));
> -
> -		gpiod_set_value_cansleep(reset_gpio, 0);
> -		if (delays[2])
> -			msleep(DIV_ROUND_UP(delays[2], 1000));
> +			gpiod_set_value_cansleep(priv->reset_gpio, 0);
> +			if (delays[2])
> +				msleep(DIV_ROUND_UP(delays[2], 1000));
> +		}
>  	}

This is not obviously correct. Sometimes it is better to change less,
so the diff is smaller, and so you can look at the diff and say, Yes,
this is obviously correct.

What is actually changing here? The devm_gpiod_get_optional() should
disappear, and reset_gpio is replaced with priv->reset_gpio. Does the
indentation need to change? Does u32 delays[3] need to move from
outside an if to inside an if?

So if i stare at this long enough it looks correct, but please try
again, and see if you can make if obviously correct.

    Andrew

---
pw-bot: cr

      reply	other threads:[~2026-04-27 12:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-27  7:50 [PATCH v3] net: stmmac: avoid repeated devm_gpiod_get_optional in mdio Liu Xiang
2026-04-27 12:54 ` Andrew Lunn [this message]

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=20472367-4e8f-457e-a87d-4c3ed8c2cad1@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=liu.xiang@zlingsmart.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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