From: Elias Pukari <elias.pukari@gmail.com>
To: netdev@vger.kernel.org
Cc: Elias Pukari <elias.pukari@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v3] net: phy: et1011c: don't write an error code to the config register
Date: Wed, 18 Nov 2026 17:07:18 +0200 [thread overview]
Message-ID: <20261118150718.16924-1-elias.pukari@gmail.com> (raw)
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
next reply other threads:[~2026-11-18 15:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 15:07 Elias Pukari [this message]
2026-11-18 15:18 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118150718.16924-1-elias.pukari@gmail.com \
--to=elias.pukari@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®