[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231220155518.15692-2-kabel@kernel.org>
Date: Wed, 20 Dec 2023 16:55:04 +0100
From: Marek Behún <kabel@...nel.org>
To: netdev@...r.kernel.org,
Andrew Lunn <andrew@...n.ch>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>
Cc: Russell King <rmk+kernel@...linux.org.uk>,
Alexander Couzens <lynxis@...0.eu>,
Daniel Golle <daniel@...rotopia.org>,
Heiner Kallweit <hkallweit1@...il.com>,
Willy Liu <willy.liu@...ltek.com>,
Ioana Ciornei <ioana.ciornei@....com>,
Marek Mojík <marek.mojik@....cz>,
Maximilián Maliar <maximilian.maliar@....cz>,
Marek Behún <kabel@...nel.org>
Subject: [PATCH net-next 01/15] net: phy: fail early with error code if indirect MMD access fails
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@...nel.org>
---
drivers/net/phy/phy-core.c | 52 +++++++++++++++++++++++++++++---------
1 file changed, 40 insertions(+), 12 deletions(-)
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);
}
/**
--
2.41.0
Powered by blists - more mailing lists