]> www.infradead.org Git - users/hch/misc.git/commitdiff
net: usb: lan78xx: fix use of improperly initialized dev->chipid in lan78xx_reset
authorI Viswanath <viswanathiyyappan@gmail.com>
Mon, 13 Oct 2025 18:16:48 +0000 (23:46 +0530)
committerJakub Kicinski <kuba@kernel.org>
Thu, 16 Oct 2025 01:27:48 +0000 (18:27 -0700)
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")
Signed-off-by: I Viswanath <viswanathiyyappan@gmail.com>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Reviewed-by: Khalid Aziz <khalid@kernel.org>
Link: https://patch.msgid.link/20251013181648.35153-1-viswanathiyyappan@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/usb/lan78xx.c

index 28195d9a8d6bc50b6d39c6ad216d0e527fc54d6c..00397a807393426d9d3c61aaf2231609f9bb461f 100644 (file)
@@ -3250,10 +3250,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)
@@ -3262,6 +3258,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)