Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christophe Roullier" <christophe.roullier@foss.st.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [net-next,PATCH v2 2/5] net: ethernet: stmmac: stm32: support the phy-supply regulator binding
Date: Thu, 13 Aug 2026 09:13:05 +0000	[thread overview]
Message-ID: <20260813091305.CD5A51F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260812091122.566439-3-christophe.roullier@foss.st.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] `phy_power_on()` unconditionally returns 0, masking regulator errors, creating dead code, and causing unbalanced disables.
- [Medium] `stm32mp1_suspend` fails to restore the PHY power state if `clk_prepare_enable` fails, leaving the device in an inconsistent state.
- [Medium] `stm32_dwmac_parse_data()` improperly masks real errors from `devm_regulator_get_optional()`, treating them as missing regulators.
--

--- Patch [2]: [net-next,PATCH v2 2/5] net: ethernet: stmmac: stm32: support the phy-supply regulator binding ---
commit 82bd267f7e4d9d57647e83b70366ec6a5796b345
Author: Christophe Roullier <christophe.roullier@foss.st.com>

net: ethernet: stmmac: stm32: support the phy-supply regulator binding

Configure the phy regulator if defined by the "phy-supply" DT phandle.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
> index e1b260ed4790b..4597f605ec1bb 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c

[ ... ]

> @@ -423,6 +425,16 @@ static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac,
>  	if (IS_ERR(dwmac->regmap))
>  		return PTR_ERR(dwmac->regmap);
>  
> +	dwmac->regulator = devm_regulator_get_optional(dev, "phy");
> +	if (IS_ERR(dwmac->regulator)) {
> +		if (PTR_ERR(dwmac->regulator) == -EPROBE_DEFER) {
> +			dev_dbg(dev, "phy regulator is not available yet, deferred probing\n");
> +			return -EPROBE_DEFER;
> +		}
> +		dev_dbg(dev, "no regulator found\n");
> +		dwmac->regulator = NULL;
> +	}
> +

[Severity: Medium]
Should this code propagate legitimate errors other than -EPROBE_DEFER and
-ENODEV?

The devm_regulator_get_optional() function returns -ENODEV if the regulator
is absent, but it can also return real errors like -ENOMEM or -EINVAL. By
treating all other errors as "no regulator found" and setting the regulator
to NULL, couldn't this hide actual initialization failures?

>  	if (dwmac->ops->is_mp2)
>  		return 0;

[ ... ]

> @@ -522,6 +534,27 @@ static int stm32_dwmac_resume(struct device *dev, void *bsp_priv)
>  	return stm32_dwmac_init(priv->plat);
>  }
>  
> +static int phy_power_on(struct stm32_dwmac *bsp_priv, bool enable)
> +{
> +	int ret;
> +	struct device *dev = bsp_priv->dev;
> +
> +	if (!bsp_priv->regulator)
> +		return 0;
> +
> +	if (enable) {
> +		ret = regulator_enable(bsp_priv->regulator);
> +		if (ret)
> +			dev_err(dev, "fail to enable phy-supply\n");
> +	} else {
> +		ret = regulator_disable(bsp_priv->regulator);
> +		if (ret)
> +			dev_err(dev, "fail to disable phy-supply\n");
> +	}
> +
> +	return 0;
> +}
> +

[Severity: Medium]
Should this function return ret instead of unconditionally returning 0?

Because it always returns 0, the caller stm32_dwmac_probe() can never see
an error, rendering its if (ret) check dead code. Furthermore, if
regulator_enable() fails, the probe will continue with an unpowered PHY,
and the teardown path might later attempt to disable a regulator that was
never successfully enabled.

[ ... ]

> @@ -614,16 +653,26 @@ static void stm32_dwmac_remove(struct platform_device *pdev)
>  		dev_pm_clear_wake_irq(&pdev->dev);
>  		device_init_wakeup(&pdev->dev, false);
>  	}
> +
> +	phy_power_on(priv->plat->bsp_priv, false);
>  }
>  
>  static int stm32mp1_suspend(struct stm32_dwmac *dwmac)
>  {
> +	/* Keep the PHY up if we use Wake-on-Lan. */
> +	if (!device_may_wakeup(dwmac->dev))
> +		phy_power_on(dwmac, false);
> +
>  	return clk_prepare_enable(dwmac->clk_ethstp);
>  }

[Severity: Medium]
Is there a missing rollback path here if clk_prepare_enable() fails?

If the clock enablement fails, the system suspend is aborted and the PM
core will not call the driver's resume callback. Since the PHY was already
powered off above, wouldn't this leave the device in an inconsistent,
non-functional state with an unpowered PHY?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260812091122.566439-1-christophe.roullier@foss.st.com?part=2

  reply	other threads:[~2026-08-13  9:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12  9:11 [net-next,PATCH v2 0/5] Some improve for STM32MP2X Christophe Roullier
2026-08-12  9:11 ` [net-next,PATCH v2 1/5] dt-bindings: net: add phy-supply property for stm32 Christophe Roullier
2026-08-12 19:58   ` Rob Herring
2026-08-12  9:11 ` [net-next,PATCH v2 2/5] net: ethernet: stmmac: stm32: support the phy-supply regulator binding Christophe Roullier
2026-08-13  9:13   ` sashiko-bot [this message]
2026-08-12  9:11 ` [net-next,PATCH v2 3/5] arm64: dts: st: add 3v3 regulator to ethernet on stm32mp235f-dk Christophe Roullier
2026-08-12  9:11 ` [net-next,PATCH v2 4/5] arm64: dts: st: add 3v3 regulator to ethernet on stm32mp257f-dk Christophe Roullier
2026-08-12  9:11 ` [net-next,PATCH v2 5/5] arm64: dts: st: increase deassert of PHY reset in stm32mp257f-ev1 Christophe Roullier

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=20260813091305.CD5A51F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=christophe.roullier@foss.st.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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