Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: microchip: Add error handling for ksz_switch_macaddr_get()

Enhance the ksz_switch_macaddr_get() function to handle errors that may
occur during the call to ksz_write8(). Specifically, this update checks
the return value of ksz_write8(), which may fail if regmap ranges
validation is not passed and returns the error code.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20231026051051.2316937-4-o.rempel@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Oleksij Rempel and committed by
Jakub Kicinski
818cdb0f 78c21fca

+13 -3
+13 -3
drivers/net/dsa/microchip/ksz_common.c
··· 3640 3640 struct ksz_switch_macaddr *switch_macaddr; 3641 3641 struct ksz_device *dev = ds->priv; 3642 3642 const u16 *regs = dev->info->regs; 3643 - int i; 3643 + int i, ret; 3644 3644 3645 3645 /* Make sure concurrent MAC address changes are blocked */ 3646 3646 ASSERT_RTNL(); ··· 3667 3667 dev->switch_macaddr = switch_macaddr; 3668 3668 3669 3669 /* Program the switch MAC address to hardware */ 3670 - for (i = 0; i < ETH_ALEN; i++) 3671 - ksz_write8(dev, regs[REG_SW_MAC_ADDR] + i, addr[i]); 3670 + for (i = 0; i < ETH_ALEN; i++) { 3671 + ret = ksz_write8(dev, regs[REG_SW_MAC_ADDR] + i, addr[i]); 3672 + if (ret) 3673 + goto macaddr_drop; 3674 + } 3672 3675 3673 3676 return 0; 3677 + 3678 + macaddr_drop: 3679 + dev->switch_macaddr = NULL; 3680 + refcount_set(&switch_macaddr->refcount, 0); 3681 + kfree(switch_macaddr); 3682 + 3683 + return ret; 3674 3684 } 3675 3685 3676 3686 void ksz_switch_macaddr_put(struct dsa_switch *ds)