Skip to content

Commit 818cdb0

Browse files
oleremkuba-moo
authored andcommitted
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 <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 78c21fc commit 818cdb0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/net/dsa/microchip/ksz_common.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,7 +3640,7 @@ int ksz_switch_macaddr_get(struct dsa_switch *ds, int port,
36403640
struct ksz_switch_macaddr *switch_macaddr;
36413641
struct ksz_device *dev = ds->priv;
36423642
const u16 *regs = dev->info->regs;
3643-
int i;
3643+
int i, ret;
36443644

36453645
/* Make sure concurrent MAC address changes are blocked */
36463646
ASSERT_RTNL();
@@ -3667,10 +3667,20 @@ int ksz_switch_macaddr_get(struct dsa_switch *ds, int port,
36673667
dev->switch_macaddr = switch_macaddr;
36683668

36693669
/* 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+
}
36723675

36733676
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;
36743684
}
36753685

36763686
void ksz_switch_macaddr_put(struct dsa_switch *ds)

0 commit comments

Comments
 (0)