diff mbox series

[net-next,v4,01/10] net: usb: lan78xx: handle errors in lan7801 PHY initialization

Message ID 20250318093410.3047828-2-o.rempel@pengutronix.de (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series Convert LAN78xx to PHYLINK | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: linux-usb@vger.kernel.org
netdev/build_clang success Errors and warnings before: 2 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 3 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 22 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2025-03-19--03-00 (tests: 894)

Commit Message

Oleksij Rempel March 18, 2025, 9:34 a.m. UTC
Add error handling for `lan78xx_write_reg()` and `lan78xx_read_reg()`
in `lan7801_phy_init()`. If any register operation fails, return
an appropriate error using `ERR_PTR(ret)` to prevent further execution
with invalid configurations.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/usb/lan78xx.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Marc Kleine-Budde March 18, 2025, 9:39 a.m. UTC | #1
On 18.03.2025 10:34:01, Oleksij Rempel wrote:
> Add error handling for `lan78xx_write_reg()` and `lan78xx_read_reg()`
> in `lan7801_phy_init()`. If any register operation fails, return
> an appropriate error using `ERR_PTR(ret)` to prevent further execution
> with invalid configurations.

You have to convert the caller of lan7801_phy_init(), too. AFICS it
checks for NULL only.

Marc

> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/usb/lan78xx.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
> index 137adf6d5b08..d03668c2c1c9 100644
> --- a/drivers/net/usb/lan78xx.c
> +++ b/drivers/net/usb/lan78xx.c
> @@ -2531,11 +2531,22 @@ static struct phy_device *lan7801_phy_init(struct lan78xx_net *dev)
>  		dev->interface = PHY_INTERFACE_MODE_RGMII;
>  		ret = lan78xx_write_reg(dev, MAC_RGMII_ID,
>  					MAC_RGMII_ID_TXC_DELAY_EN_);
> +		if (ret < 0)
> +			return ERR_PTR(ret);
> +
>  		ret = lan78xx_write_reg(dev, RGMII_TX_BYP_DLL, 0x3D00);
> +		if (ret < 0)
> +			return ERR_PTR(ret);
> +
>  		ret = lan78xx_read_reg(dev, HW_CFG, &buf);
> +		if (ret < 0)
> +			return ERR_PTR(ret);
> +
>  		buf |= HW_CFG_CLK125_EN_;
>  		buf |= HW_CFG_REFCLK25_EN_;
>  		ret = lan78xx_write_reg(dev, HW_CFG, buf);
> +		if (ret < 0)
> +			return ERR_PTR(ret);
>  	} else {
>  		if (!phydev->drv) {
>  			netdev_err(dev->net, "no PHY driver found\n");
> -- 
> 2.39.5
> 
> 
>
diff mbox series

Patch

diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 137adf6d5b08..d03668c2c1c9 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -2531,11 +2531,22 @@  static struct phy_device *lan7801_phy_init(struct lan78xx_net *dev)
 		dev->interface = PHY_INTERFACE_MODE_RGMII;
 		ret = lan78xx_write_reg(dev, MAC_RGMII_ID,
 					MAC_RGMII_ID_TXC_DELAY_EN_);
+		if (ret < 0)
+			return ERR_PTR(ret);
+
 		ret = lan78xx_write_reg(dev, RGMII_TX_BYP_DLL, 0x3D00);
+		if (ret < 0)
+			return ERR_PTR(ret);
+
 		ret = lan78xx_read_reg(dev, HW_CFG, &buf);
+		if (ret < 0)
+			return ERR_PTR(ret);
+
 		buf |= HW_CFG_CLK125_EN_;
 		buf |= HW_CFG_REFCLK25_EN_;
 		ret = lan78xx_write_reg(dev, HW_CFG, buf);
+		if (ret < 0)
+			return ERR_PTR(ret);
 	} else {
 		if (!phydev->drv) {
 			netdev_err(dev->net, "no PHY driver found\n");