netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: phy: at803x: fix probe error if copper page is selected
@ 2021-04-20 10:29 Michael Walle
  2021-04-20 11:04 ` David Bauer
  2021-04-21  0:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Walle @ 2021-04-20 10:29 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: Andrew Lunn, Heiner Kallweit, Russell King, David S . Miller,
	Jakub Kicinski, David Bauer, Michael Walle

The commit c329e5afb42f ("net: phy: at803x: select correct page on
config init") selects the copper page during probe. This fails if the
copper page was already selected. In this case, the value of the copper
page (which is 1) is propagated through phy_restore_page() and is
finally returned for at803x_probe(). Fix it, by just using the
at803x_page_write() directly.

Also in case of an error, the regulator is not disabled and leads to a
WARN_ON() when the probe fails. This couldn't happen before, because
at803x_parse_dt() was the last call in at803x_probe(). It is hard to
see, that the parse_dt() actually enables the regulator. Thus move the
regulator_enable() to the probe function and undo it in case of an
error.

Fixes: c329e5afb42f ("net: phy: at803x: select correct page on config init")
Signed-off-by: Michael Walle <michael@walle.cc>
---
Changes since v1:
 - take the bus lock

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

diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index e0f56850edc5..32af52dd5aed 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -554,10 +554,6 @@ static int at803x_parse_dt(struct phy_device *phydev)
 			phydev_err(phydev, "failed to get VDDIO regulator\n");
 			return PTR_ERR(priv->vddio);
 		}
-
-		ret = regulator_enable(priv->vddio);
-		if (ret < 0)
-			return ret;
 	}
 
 	return 0;
@@ -579,15 +575,30 @@ static int at803x_probe(struct phy_device *phydev)
 	if (ret)
 		return ret;
 
+	if (priv->vddio) {
+		ret = regulator_enable(priv->vddio);
+		if (ret < 0)
+			return ret;
+	}
+
 	/* Some bootloaders leave the fiber page selected.
 	 * Switch to the copper page, as otherwise we read
 	 * the PHY capabilities from the fiber side.
 	 */
 	if (at803x_match_phy_id(phydev, ATH8031_PHY_ID)) {
-		ret = phy_select_page(phydev, AT803X_PAGE_COPPER);
-		ret = phy_restore_page(phydev, AT803X_PAGE_COPPER, ret);
+		phy_lock_mdio_bus(phydev);
+		ret = at803x_write_page(phydev, AT803X_PAGE_COPPER);
+		phy_unlock_mdio_bus(phydev);
+		if (ret)
+			goto err;
 	}
 
+	return 0;
+
+err:
+	if (priv->vddio)
+		regulator_disable(priv->vddio);
+
 	return ret;
 }
 
-- 
2.20.1


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

* Re: [PATCH net-next v2] net: phy: at803x: fix probe error if copper page is selected
  2021-04-20 10:29 [PATCH net-next v2] net: phy: at803x: fix probe error if copper page is selected Michael Walle
@ 2021-04-20 11:04 ` David Bauer
  2021-04-21  0:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: David Bauer @ 2021-04-20 11:04 UTC (permalink / raw)
  To: Michael Walle, netdev, linux-kernel
  Cc: Andrew Lunn, Heiner Kallweit, Russell King, David S . Miller,
	Jakub Kicinski

Hi,

On 4/20/21 12:29 PM, Michael Walle wrote:
> The commit c329e5afb42f ("net: phy: at803x: select correct page on
> config init") selects the copper page during probe. This fails if the
> copper page was already selected. In this case, the value of the copper
> page (which is 1) is propagated through phy_restore_page() and is
> finally returned for at803x_probe(). Fix it, by just using the
> at803x_page_write() directly.

Ouch, i didn't spot that. Thanks for taking care.

> 
> Also in case of an error, the regulator is not disabled and leads to a
> WARN_ON() when the probe fails. This couldn't happen before, because
> at803x_parse_dt() was the last call in at803x_probe(). It is hard to
> see, that the parse_dt() actually enables the regulator. Thus move the
> regulator_enable() to the probe function and undo it in case of an
> error.
> 
> Fixes: c329e5afb42f ("net: phy: at803x: select correct page on config init")
> Signed-off-by: Michael Walle <michael@walle.cc>

Reviewed-by: David Bauer <mail@david-bauer.net>

Best
David

> ---
> Changes since v1:
>  - take the bus lock
> 
>  drivers/net/phy/at803x.c | 23 +++++++++++++++++------
>  1 file changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
> index e0f56850edc5..32af52dd5aed 100644
> --- a/drivers/net/phy/at803x.c
> +++ b/drivers/net/phy/at803x.c
> @@ -554,10 +554,6 @@ static int at803x_parse_dt(struct phy_device *phydev)
>  			phydev_err(phydev, "failed to get VDDIO regulator\n");
>  			return PTR_ERR(priv->vddio);
>  		}
> -
> -		ret = regulator_enable(priv->vddio);
> -		if (ret < 0)
> -			return ret;
>  	}
>  
>  	return 0;
> @@ -579,15 +575,30 @@ static int at803x_probe(struct phy_device *phydev)
>  	if (ret)
>  		return ret;
>  
> +	if (priv->vddio) {
> +		ret = regulator_enable(priv->vddio);
> +		if (ret < 0)
> +			return ret;
> +	}
> +
>  	/* Some bootloaders leave the fiber page selected.
>  	 * Switch to the copper page, as otherwise we read
>  	 * the PHY capabilities from the fiber side.
>  	 */
>  	if (at803x_match_phy_id(phydev, ATH8031_PHY_ID)) {
> -		ret = phy_select_page(phydev, AT803X_PAGE_COPPER);
> -		ret = phy_restore_page(phydev, AT803X_PAGE_COPPER, ret);
> +		phy_lock_mdio_bus(phydev);
> +		ret = at803x_write_page(phydev, AT803X_PAGE_COPPER);
> +		phy_unlock_mdio_bus(phydev);
> +		if (ret)
> +			goto err;
>  	}
>  
> +	return 0;
> +
> +err:
> +	if (priv->vddio)
> +		regulator_disable(priv->vddio);
> +
>  	return ret;
>  }
>  
> 

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

* Re: [PATCH net-next v2] net: phy: at803x: fix probe error if copper page is selected
  2021-04-20 10:29 [PATCH net-next v2] net: phy: at803x: fix probe error if copper page is selected Michael Walle
  2021-04-20 11:04 ` David Bauer
@ 2021-04-21  0:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-04-21  0:10 UTC (permalink / raw)
  To: Michael Walle
  Cc: netdev, linux-kernel, andrew, hkallweit1, linux, davem, kuba, mail

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Tue, 20 Apr 2021 12:29:29 +0200 you wrote:
> The commit c329e5afb42f ("net: phy: at803x: select correct page on
> config init") selects the copper page during probe. This fails if the
> copper page was already selected. In this case, the value of the copper
> page (which is 1) is propagated through phy_restore_page() and is
> finally returned for at803x_probe(). Fix it, by just using the
> at803x_page_write() directly.
> 
> [...]

Here is the summary with links:
  - [net-next,v2] net: phy: at803x: fix probe error if copper page is selected
    https://git.kernel.org/netdev/net-next/c/8f7e876273e2

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-04-21  0:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 10:29 [PATCH net-next v2] net: phy: at803x: fix probe error if copper page is selected Michael Walle
2021-04-20 11:04 ` David Bauer
2021-04-21  0:10 ` patchwork-bot+netdevbpf

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