🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Elias Pukari Wed, 18 Nov 2026 15:07
[PATCH net-next v3] net: phy: et1011c: don't write an error code to the config register
#18589
Author: Elias Pukari
Date: Wed, 18 Nov 2026 15:07
90 lines
13384 bytes
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
Re: [PATCH net-next v3] net: phy: et1011c: don't write an error code to the config register
#18601
Author: Andrew Lunn
Date: Wed, 18 Nov 2026 15:18
41 lines
9351 bytes
> +static int et1011c_probe(struct phy_device *phydev)
> +{
> +	phydev->priv = devm_kzalloc_obj(&phydev->mdio.dev, int);
> +	return phydev->priv ? 0 : -ENOMEM;

Look at other kernel code. And in look mostly at phy drivers. How
often do you see this sort of return code?

You want your code to look like all the other code.

Also, how often do you see a priv which is not structure?

>  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;
> +	}

Look at other users of genphy_read_status(). How many have code like
this? If you are doing something which no other driver does, it is
likely to be wrong.

    Andrew

---
pw-bot: cr
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads