From a188536ef6507e30cba218182e673349ea48cbe7 Mon Sep 17 00:00:00 2001 From: Pascal Ernster Date: Thu, 5 Jan 2023 06:35:35 +0100 Subject: [PATCH] realtek: 5.15: Improve rtl838x dsa driver error handling Make sure functions calling rtl838x_smi_wait_op() return its return value in target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.c. This brings the code style in line with the rtl839x implementation. Suggested-by: Sander Vanheule Signed-off-by: Pascal Ernster --- .../drivers/net/dsa/rtl83xx/rtl838x.c | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.c b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.c index cbd4543db4..8a162df9a4 100644 --- a/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.c +++ b/target/linux/realtek/files-5.15/drivers/net/dsa/rtl83xx/rtl838x.c @@ -1798,7 +1798,7 @@ int rtl838x_smi_wait_op(int timeout) /* Reads a register in a page from the PHY */ int rtl838x_read_phy(u32 port, u32 page, u32 reg, u32 *val) { - int err = -ETIMEDOUT; + int err; u32 v; u32 park_page; @@ -1812,8 +1812,9 @@ int rtl838x_read_phy(u32 port, u32 page, u32 reg, u32 *val) mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(100000)) - goto timeout; + err = rtl838x_smi_wait_op(100000); + if (err) + goto errout; sw_w32_mask(0xffff0000, port << 16, RTL838X_SMI_ACCESS_PHY_CTRL_2); @@ -1822,14 +1823,15 @@ int rtl838x_read_phy(u32 port, u32 page, u32 reg, u32 *val) sw_w32(v | park_page, RTL838X_SMI_ACCESS_PHY_CTRL_1); sw_w32_mask(0, 1, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(100000)) - goto timeout; + err = rtl838x_smi_wait_op(100000); + if (err) + goto errout; *val = sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_2) & 0xffff; err = 0; -timeout: +errout: mutex_unlock(&smi_lock); return err; @@ -1838,7 +1840,7 @@ timeout: /* Write to a register in a page of the PHY */ int rtl838x_write_phy(u32 port, u32 page, u32 reg, u32 val) { - int err = -ETIMEDOUT; + int err; u32 v; u32 park_page; @@ -1847,8 +1849,9 @@ int rtl838x_write_phy(u32 port, u32 page, u32 reg, u32 val) return -ENOTSUPP; mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(100000)) - goto timeout; + err = rtl838x_smi_wait_op(100000); + if (err) + goto errout; sw_w32(BIT(port), RTL838X_SMI_ACCESS_PHY_CTRL_0); mdelay(10); @@ -1860,12 +1863,13 @@ int rtl838x_write_phy(u32 port, u32 page, u32 reg, u32 val) sw_w32(v | park_page, RTL838X_SMI_ACCESS_PHY_CTRL_1); sw_w32_mask(0, 1, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(100000)) - goto timeout; + err = rtl838x_smi_wait_op(100000); + if (err) + goto errout; err = 0; -timeout: +errout: mutex_unlock(&smi_lock); return err; @@ -1874,13 +1878,14 @@ timeout: /* Read an mmd register of a PHY */ int rtl838x_read_mmd_phy(u32 port, u32 addr, u32 reg, u32 *val) { - int err = -ETIMEDOUT; + int err; u32 v; mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(100000)) - goto timeout; + err = rtl838x_smi_wait_op(100000); + if (err) + goto errout; sw_w32(1 << port, RTL838X_SMI_ACCESS_PHY_CTRL_0); mdelay(10); @@ -1894,14 +1899,15 @@ int rtl838x_read_mmd_phy(u32 port, u32 addr, u32 reg, u32 *val) v = 1 << 1 | 0 << 2 | 1; sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(100000)) - goto timeout; + err = rtl838x_smi_wait_op(100000); + if (err) + goto errout; *val = sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_2) & 0xffff; err = 0; -timeout: +errout: mutex_unlock(&smi_lock); return err; @@ -1910,15 +1916,16 @@ timeout: /* Write to an mmd register of a PHY */ int rtl838x_write_mmd_phy(u32 port, u32 addr, u32 reg, u32 val) { - int err = -ETIMEDOUT; + int err; u32 v; pr_debug("MMD write: port %d, dev %d, reg %d, val %x\n", port, addr, reg, val); val &= 0xffff; mutex_lock(&smi_lock); - if (rtl838x_smi_wait_op(100000)) - goto timeout; + err = rtl838x_smi_wait_op(100000); + if (err) + goto errout; sw_w32(1 << port, RTL838X_SMI_ACCESS_PHY_CTRL_0); mdelay(10); @@ -1931,12 +1938,13 @@ int rtl838x_write_mmd_phy(u32 port, u32 addr, u32 reg, u32 val) v = 1 << 1 | 1 << 2 | 1; sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_1); - if (rtl838x_smi_wait_op(100000)) - goto timeout; + err = rtl838x_smi_wait_op(100000); + if (err) + goto errout; err = 0; -timeout: +errout: mutex_unlock(&smi_lock); return err; } -- 2.30.2