* [PATCH net-next v3] net: phy: et1011c: don't write an error code to the config register
@ 2026-11-18 15:07 Elias Pukari
0 siblings, 0 replies; only message in thread
From: Elias Pukari @ 2026-11-18 15:07 UTC (permalink / raw)
To: netdev
Cc: Elias Pukari, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel
et1011c_read_status() can write a read error to the config register.
Return MDIO errors and cache each PHY's speed only after configuration
succeeds.
LLM helped
Found by code inspection. Tested with MDIO error injection in KUnit
under QEMU/KASAN. No hardware or kselftest run.
Signed-off-by: Elias Pukari <elias.pukari@gmail.com>
---
Full builds unverified due to warnings on the unpatched base.
https://lore.kernel.org/netdev/20261115180735.649299-1-elias.pukari@gmail.com/
drivers/net/phy/et1011c.c | 37 ++++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 11 deletions(-)
diff --git a/drivers/net/phy/et1011c.c b/drivers/net/phy/et1011c.c
index 6cd8d7758..77a6e8dcf 100644
--- a/drivers/net/phy/et1011c.c
+++ b/drivers/net/phy/et1011c.c
@@ -44,6 +44,12 @@ MODULE_DESCRIPTION("LSI ET1011C PHY driver");
MODULE_AUTHOR("Chaithrika U S");
MODULE_LICENSE("GPL");
+static int et1011c_probe(struct phy_device *phydev)
+{
+ phydev->priv = devm_kzalloc_obj(&phydev->mdio.dev, int);
+ return phydev->priv ? 0 : -ENOMEM;
+}
+
static int et1011c_config_aneg(struct phy_device *phydev)
{
int ctl = phy_read(phydev, MII_BMCR);
@@ -60,25 +66,33 @@ static int et1011c_config_aneg(struct phy_device *phydev)
static int et1011c_read_status(struct phy_device *phydev)
{
- static int speed;
+ int *configured_speed = phydev->priv;
+ bool was_up = phydev->link;
+ int val;
int ret;
- u32 val;
ret = genphy_read_status(phydev);
+ if (ret < 0 || !phydev->link) {
+ *configured_speed = SPEED_UNKNOWN;
+ return ret;
+ }
- if (speed != phydev->speed) {
- speed = phydev->speed;
+ if (!was_up || *configured_speed <= 0 ||
+ *configured_speed != phydev->speed) {
+ *configured_speed = SPEED_UNKNOWN;
val = phy_read(phydev, ET1011C_STATUS_REG);
+ if (val < 0)
+ return val;
+
if ((val & ET1011C_SPEED_MASK) ==
ET1011C_GIGABIT_SPEED) {
- val = phy_read(phydev, ET1011C_CONFIG_REG);
- val &= ~ET1011C_TX_FIFO_MASK;
- phy_write(phydev, ET1011C_CONFIG_REG, val |
- ET1011C_GMII_INTERFACE |
- ET1011C_SYS_CLK_EN |
- ET1011C_TX_FIFO_DEPTH_16);
-
+ ret = phy_modify(phydev, ET1011C_CONFIG_REG,
+ ET1011C_TX_FIFO_MASK, ET1011C_GMII_INTERFACE |
+ ET1011C_SYS_CLK_EN | ET1011C_TX_FIFO_DEPTH_16);
+ if (ret < 0)
+ return ret;
}
+ *configured_speed = phydev->speed;
}
return ret;
}
@@ -88,6 +102,7 @@ static struct phy_driver et1011c_driver[] = { {
.name = "ET1011C",
.phy_id_mask = 0xfffffff0,
/* PHY_GBIT_FEATURES */
+ .probe = et1011c_probe,
.config_aneg = et1011c_config_aneg,
.read_status = et1011c_read_status,
} };
base-commit: d6816d9a93b66a12bf01e10037e377f3333ad6cc
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-18 15:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 15:07 [PATCH net-next v3] net: phy: et1011c: don't write an error code to the config register Elias Pukari
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®