diff mbox series

[net-next,01/15] net: phy: fail early with error code if indirect MMD access fails

Message ID 20231220155518.15692-2-kabel@kernel.org (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Realtek RTL822x PHY rework to c45 and SerDes interface switching | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
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: 1115 this patch: 1115
netdev/cc_maintainers warning 1 maintainers not CCed: edumazet@google.com
netdev/build_clang fail Errors and warnings before: 12 this patch: 12
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: 1142 this patch: 1142
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 76 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

Commit Message

Marek Behún Dec. 20, 2023, 3:55 p.m. UTC
Check return values of __mdiobus_write() in mmd_phy_indirect() and
return value of mmd_phy_indirect() itself.

Signed-off-by: Marek Behún <kabel@kernel.org>
---
 drivers/net/phy/phy-core.c | 52 +++++++++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 12 deletions(-)

Comments

Russell King (Oracle) Jan. 2, 2024, 11:09 a.m. UTC | #1
On Wed, Dec 20, 2023 at 04:55:04PM +0100, Marek Behún wrote:
> Check return values of __mdiobus_write() in mmd_phy_indirect() and
> return value of mmd_phy_indirect() itself.
> 
> Signed-off-by: Marek Behún <kabel@kernel.org>

I think the reason it was done this way is based on the reasoning that
if the bus has failed then the last read/write will also fail. However,
if we had a spurious failure (and they _do_ happen) then one of the
previous writes e.g. to the indirect address register could have failed
and we could end up corrupting a different register.

Therefore, this makes sense (and some of my commentry should probably
be in the patch description to explain why the change is being made.)

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Thanks!
diff mbox series

Patch

diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
index 15f349e5995a..9318b65cca95 100644
--- a/drivers/net/phy/phy-core.c
+++ b/drivers/net/phy/phy-core.c
@@ -526,18 +526,50 @@  int phy_speed_down_core(struct phy_device *phydev)
 	return 0;
 }
 
-static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad,
-			     u16 regnum)
+static int mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad,
+			    u16 regnum)
 {
+	int ret;
+
 	/* Write the desired MMD Devad */
-	__mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad);
+	ret = __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad);
+	if (ret < 0)
+		return ret;
 
 	/* Write the desired MMD register address */
-	__mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum);
+	ret = __mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum);
+	if (ret < 0)
+		return ret;
 
 	/* Select the Function : DATA with no post increment */
-	__mdiobus_write(bus, phy_addr, MII_MMD_CTRL,
-			devad | MII_MMD_CTRL_NOINCR);
+	return __mdiobus_write(bus, phy_addr, MII_MMD_CTRL,
+			       devad | MII_MMD_CTRL_NOINCR);
+}
+
+static int mmd_phy_read_indirect(struct mii_bus *bus, int phy_addr, int devad,
+				 u32 regnum)
+{
+	int ret;
+
+	ret = mmd_phy_indirect(bus, phy_addr, devad, regnum);
+	if (ret < 0)
+		return ret;
+
+	/* Read the content of the MMD's selected register */
+	return __mdiobus_read(bus, phy_addr, MII_MMD_DATA);
+}
+
+static int mmd_phy_write_indirect(struct mii_bus *bus, int phy_addr, int devad,
+				  u32 regnum, u16 val)
+{
+	int ret;
+
+	ret = mmd_phy_indirect(bus, phy_addr, devad, regnum);
+	if (ret < 0)
+		return ret;
+
+	/* Write the data into MMD's selected register */
+	return __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);
 }
 
 static int mmd_phy_read(struct mii_bus *bus, int phy_addr, bool is_c45,
@@ -546,9 +578,7 @@  static int mmd_phy_read(struct mii_bus *bus, int phy_addr, bool is_c45,
 	if (is_c45)
 		return __mdiobus_c45_read(bus, phy_addr, devad, regnum);
 
-	mmd_phy_indirect(bus, phy_addr, devad, regnum);
-	/* Read the content of the MMD's selected register */
-	return __mdiobus_read(bus, phy_addr, MII_MMD_DATA);
+	return mmd_phy_read_indirect(bus, phy_addr, devad, regnum);
 }
 
 static int mmd_phy_write(struct mii_bus *bus, int phy_addr, bool is_c45,
@@ -557,9 +587,7 @@  static int mmd_phy_write(struct mii_bus *bus, int phy_addr, bool is_c45,
 	if (is_c45)
 		return __mdiobus_c45_write(bus, phy_addr, devad, regnum, val);
 
-	mmd_phy_indirect(bus, phy_addr, devad, regnum);
-	/* Write the data into MMD's selected register */
-	return __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);
+	return mmd_phy_write_indirect(bus, phy_addr, devad, regnum, val);
 }
 
 /**