Skip to contentSkip to conversation

net: usb: lan78xx: fix use of improperly initialized dev->chipid in lan78xx_reset

PATCH Applied I Viswanath 4 participants 7 messages Oct 13, 2025 – Oct 16, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: usb: lan78xx: fix use of improperly initialized dev->chipid in lan78xx_reset

dev->chipid is used in lan78xx_init_mac_address before it's initialized:

lan78xx_reset() {
    lan78xx_init_mac_address()
        lan78xx_read_eeprom()
            lan78xx_read_raw_eeprom() <- dev->chipid is used here

    dev->chipid = ... <- dev->chipid is initialized correctly here
}

Reorder initialization so that dev->chipid is set before calling lan78xx_init_mac_address().

Fixes a0db7d10b76e ("lan78xx: Add to handle mux control per chip id")

---
v1:

v2:
- Add Fixes tag

 drivers/net/usb/lan78xx.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/usb/lan78xx.c +4 -4
index 42d35cc6b421..b4b086f86ed8 100644
@@ -3247,10 +3247,6 @@ static int lan78xx_reset(struct lan78xx_net *dev)
 		}
 	} while (buf & HW_CFG_LRST_);
 
-	ret = lan78xx_init_mac_address(dev);
-	if (ret < 0)
-		return ret;
-
 	/* save DEVID for later usage */
 	ret = lan78xx_read_reg(dev, ID_REV, &buf);
 	if (ret < 0)
@@ -3259,6 +3255,10 @@ static int lan78xx_reset(struct lan78xx_net *dev)
 	dev->chipid = (buf & ID_REV_CHIP_ID_MASK_) >> 16;
 	dev->chiprev = buf & ID_REV_CHIP_REV_MASK_;
 
+	ret = lan78xx_init_mac_address(dev);
+	if (ret < 0)
+		return ret;
+
 	/* Respond to the IN token with a NAK */
 	ret = lan78xx_read_reg(dev, USB_CFG0, &buf);
 	if (ret < 0)
Signature · 1 line
2.47.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · I Viswanath

dev->chipid is used in lan78xx_init_mac_address before it's initialized:

lan78xx_reset() {
     lan78xx_init_mac_address()
         lan78xx_read_eeprom()
             lan78xx_read_raw_eeprom() <- dev->chipid is used here

     dev->chipid = ... <- dev->chipid is initialized correctly here
}
Quoted 5 lines

Reorder initialization so that dev->chipid is set before calling lan78xx_init_mac_address().

Fixes a0db7d10b76e ("lan78xx: Add to handle mux control per chip id")
#2 lore raw
In reply to I Viswanath
Quoted 10 lines · I Viswanath

dev->chipid is used in lan78xx_init_mac_address before it's initialized:

lan78xx_reset() {
     lan78xx_init_mac_address()
         lan78xx_read_eeprom()
             lan78xx_read_raw_eeprom() <- dev->chipid is used here

     dev->chipid = ... <- dev->chipid is initialized correctly here
}
Quoted 4 lines

Reorder initialization so that dev->chipid is set before calling lan78xx_init_mac_address().

Fixes a0db7d10b76e ("lan78xx: Add to handle mux control per chip id")

How did you determine this is the commit that introduced this bug?

From what I can see, commit a0db7d10b76e does not touch lan78xx_reset() function. This bug was introduced when devid was replaced by chipid (commit 87177ba6e47e "lan78xx: replace devid to chipid & chiprev") or even earlier when the order of calls to lan78xx_init_mac_address() and lan78xx_read_reg() was introduced in lan78xx_reset() depending upon if lan78xx_init_mac_address() at that time used devid in its call sequence at the time.

--
Khalid

Quoted 37 lines

---
v1:

v2:
- Add Fixes tag

  drivers/net/usb/lan78xx.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/usb/lan78xx.c +4 -4
index 42d35cc6b421..b4b086f86ed8 100644
@@ -3247,10 +3247,6 @@ static int lan78xx_reset(struct lan78xx_net *dev)
  		}
  	} while (buf & HW_CFG_LRST_);
 
-	ret = lan78xx_init_mac_address(dev);
-	if (ret < 0)
-		return ret;
-
  	/* save DEVID for later usage */
  	ret = lan78xx_read_reg(dev, ID_REV, &buf);
  	if (ret < 0)
@@ -3259,6 +3255,10 @@ static int lan78xx_reset(struct lan78xx_net *dev)
  	dev->chipid = (buf & ID_REV_CHIP_ID_MASK_) >> 16;
  	dev->chiprev = buf & ID_REV_CHIP_REV_MASK_;
 
+	ret = lan78xx_init_mac_address(dev);
+	if (ret < 0)
+		return ret;
+
  	/* Respond to the IN token with a NAK */
  	ret = lan78xx_read_reg(dev, USB_CFG0, &buf);
  	if (ret < 0)
#3 lore raw
Quoted 9 lines · Khalid Aziz

How did you determine this is the commit that introduced this bug?

From what I can see, commit a0db7d10b76e does not touch lan78xx_reset()
function. This bug was introduced when devid was replaced by chipid (commit 87177ba6e47e "lan78xx: replace devid to chipid & chiprev") or even earlier when the order of calls to lan78xx_init_mac_address() and lan78xx_read_reg() was introduced in lan78xx_reset() depending upon if lan78xx_init_mac_address() at that time used devid in its call sequence at the time.

The commit a0db7d10b76e introduced the dependency on devid to lan78xx_read_raw_eeprom() and
lan78xx_read_eeprom() and ultimately lan78xx_init_mac_address() and lan78xx_reset()

In lan78xx_init_mac_address()

Only lan78xx_read_eeprom() depends on devid as

lan78xx_read_reg() and lan78xx_write_reg() do not use devid

lan78xx_read_otp() depends on lan78xx_read_raw_otp() which depends only on lan78xx_write_reg() and lan78xx_read_reg()
and hence doesn't use devid either

is_valid_ether_addr(), random_ether_addr() and ether_addr_copy() are net core functions and do not care about driver specific data

The devid read exists in this commit (was added in ce85e13ad6ef4)

a0db7d10b76e was supposed to move the devid read before the lan78xx_init_mac_address() because of the newly added dependency but it was a tricky detail that the author failed to see

Thanks,
I Viswanath

#4 lore raw
Quoted 30 lines · I Viswanath
Quoted 9 lines · Khalid Aziz

How did you determine this is the commit that introduced this bug?

From what I can see, commit a0db7d10b76e does not touch lan78xx_reset()
function. This bug was introduced when devid was replaced by chipid (commit 87177ba6e47e "lan78xx: replace devid to chipid & chiprev") or even earlier when the order of calls to lan78xx_init_mac_address() and lan78xx_read_reg() was introduced in lan78xx_reset() depending upon if lan78xx_init_mac_address() at that time used devid in its call sequence at the time.

The commit a0db7d10b76e introduced the dependency on devid to lan78xx_read_raw_eeprom() and
lan78xx_read_eeprom() and ultimately lan78xx_init_mac_address() and lan78xx_reset()

In lan78xx_init_mac_address()

Only lan78xx_read_eeprom() depends on devid as

lan78xx_read_reg() and lan78xx_write_reg() do not use devid

lan78xx_read_otp() depends on lan78xx_read_raw_otp() which depends only on lan78xx_write_reg() and lan78xx_read_reg()
and hence doesn't use devid either

is_valid_ether_addr(), random_ether_addr() and ether_addr_copy() are net core functions and do not care about driver specific data

Quoted 8 lines

The devid read exists in this commit (was added in ce85e13ad6ef4)

a0db7d10b76e was supposed to move the devid read before the lan78xx_init_mac_address() because of the newly added dependency but it was a tricky detail that the author failed to see

Thanks,
I Viswanath

Ah, I see. That makes sense.

--
Khalid

Reviewed-by on v2 1/1
#5 lore raw
In reply to I Viswanath
Quoted 41 lines · I Viswanath

dev->chipid is used in lan78xx_init_mac_address before it's initialized:

lan78xx_reset() {
     lan78xx_init_mac_address()
         lan78xx_read_eeprom()
             lan78xx_read_raw_eeprom() <- dev->chipid is used here

     dev->chipid = ... <- dev->chipid is initialized correctly here
}

Reorder initialization so that dev->chipid is set before calling lan78xx_init_mac_address().

Fixes a0db7d10b76e ("lan78xx: Add to handle mux control per chip id")

---
v1:

v2:
- Add Fixes tag

  drivers/net/usb/lan78xx.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/usb/lan78xx.c +0 -4
index 42d35cc6b421..b4b086f86ed8 100644
@@ -3247,10 +3247,6 @@ static int lan78xx_reset(struct lan78xx_net *dev)
  		}
  	} while (buf & HW_CFG_LRST_);
 
-	ret = lan78xx_init_mac_address(dev);
-	if (ret < 0)
-		return ret;
-
  	/* save DEVID for later usage */
  	ret = lan78xx_read_reg(dev, ID_REV, &buf);
  	if (ret < 0)

drivers/net/usb/lan78xx.c static int lan78xx_reset(struct lan78xx_net *dev) · line 3264

Quoted 10 lines
drivers/net/usb/lan78xx.c +4 -0
@@ -3259,6 +3255,10 @@ static int lan78xx_reset(struct lan78xx_net *dev)
  	dev->chipid = (buf & ID_REV_CHIP_ID_MASK_) >> 16;
  	dev->chiprev = buf & ID_REV_CHIP_REV_MASK_;
 
+	ret = lan78xx_init_mac_address(dev);
+	if (ret < 0)
+		return ret;
+
  	/* Respond to the IN token with a NAK */
  	ret = lan78xx_read_reg(dev, USB_CFG0, &buf);
  	if (ret < 0)

Looks good to me.

--
Khalid

#6 lore raw
In reply to I Viswanath
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 13 Oct 2025 23:46:48 +0530 you wrote:

dev->chipid is used in lan78xx_init_mac_address before it's initialized:

lan78xx_reset() {
    lan78xx_init_mac_address()
        lan78xx_read_eeprom()
            lan78xx_read_raw_eeprom() <- dev->chipid is used here

[...]

Here is the summary with links:
- [net,v2] net: usb: lan78xx: fix use of improperly initialized dev->chipid in lan78xx_reset

    https://git.kernel.org/netdev/net/c/8d93ff40d49d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html