[PATCH] phy: berlin-sata: count available child nodes

sashiko-bot at kernel.org sashiko-bot at kernel.org
Thu Nov 19 00:23:15 PST 2026


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] phy: berlin-sata: wrong bounds check in
  phy_berlin_sata_phy_xlate()
--

commit 0529df9ae940f51aa712838077eb6b3ead50665d
Author: Wang Haoran <wanghr2026 at mail.zgclab.edu.cn>

phy: berlin-sata: count available child nodes

This commit sizes priv->nphys with of_get_available_child_count() so that
priv->phys[] matches the number of available child nodes populated during
probe.

> diff --git a/drivers/phy/marvell/phy-berlin-sata.c b/drivers/phy/marvell/phy-berlin-sata.c
> index c90e2867900c3..1d3afc2eb9535 100644
> --- a/drivers/phy/marvell/phy-berlin-sata.c
> +++ b/drivers/phy/marvell/phy-berlin-sata.c
> @@ -212,7 +212,7 @@ static int phy_berlin_sata_probe(struct platform_device *pdev)
>  	if (IS_ERR(priv->clk))
>  		return PTR_ERR(priv->clk);
>  
> -	priv->nphys = of_get_child_count(dev->of_node);
> +	priv->nphys = of_get_available_child_count(dev->of_node);
>  	if (priv->nphys == 0)
>  		return -ENODEV;

[Severity: Medium]
Does shrinking priv->nphys to the available child count break lookups of
PHY 1 when PHY 0 is disabled?

drivers/phy/marvell/phy-berlin-sata.c:phy_berlin_sata_phy_xlate() {
    ...
	if (WARN_ON(args->args[0] >= priv->nphys))
		return ERR_PTR(-ENODEV);

	for (i = 0; i < priv->nphys; i++) {
		if (priv->phys[i]->index == args->args[0])
			break;
	}
    ...
}

args->args[0] is the hardware PHY index (0 or 1), which the loop matches
against priv->phys[i]->index.  When PHY 0 is disabled and PHY 1 is enabled,
priv->nphys is 1 and priv->phys[0]->index is 1, so requesting PHY 1 trips
WARN_ON(args->args[0] >= priv->nphys) and fails with -ENODEV before reaching
the lookup loop.

Should phy_berlin_sata_phy_xlate() bound-check args->args[0] against
ARRAY_SIZE(phy_berlin_power_down_bits), matching phy_berlin_sata_probe()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/1795076106646-11-85fca065@mail.zgclab.edu.cn?part=1



More information about the linux-phy mailing list