net: dsa: microchip: ksz8: Refactor ksz8_fdb_dump()
Refactor ksz8_fdb_dump() to address potential issues: - Limit the number of iterations to avoid endless loops. - Handle error codes returned by ksz8_r_dyn_mac_table(), with an exception for -ENXIO when no more dynamic entries are detected. Reviewed-by: Vladimir Oltean <olteanv@gmail.com> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> Acked-by: Arun Ramadoss <arun.ramadoss@microchip.com> Link: https://lore.kernel.org/r/20240403125039.3414824-4-o.rempel@pengutronix.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
860cf29eab
commit
0499bb09f4
@@ -1191,27 +1191,30 @@ void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
|
||||
int ksz8_fdb_dump(struct ksz_device *dev, int port,
|
||||
dsa_fdb_dump_cb_t *cb, void *data)
|
||||
{
|
||||
int ret = 0;
|
||||
u16 i = 0;
|
||||
u16 entries = 0;
|
||||
u8 fid;
|
||||
u8 src_port;
|
||||
u8 mac[ETH_ALEN];
|
||||
u8 src_port, fid;
|
||||
u16 entries = 0;
|
||||
int ret, i;
|
||||
|
||||
do {
|
||||
for (i = 0; i < KSZ8_DYN_MAC_ENTRIES; i++) {
|
||||
ret = ksz8_r_dyn_mac_table(dev, i, mac, &fid, &src_port,
|
||||
&entries);
|
||||
if (!ret && port == src_port) {
|
||||
if (ret == -ENXIO)
|
||||
return 0;
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (i >= entries)
|
||||
return 0;
|
||||
|
||||
if (port == src_port) {
|
||||
ret = cb(mac, fid, false, data);
|
||||
if (ret)
|
||||
break;
|
||||
return ret;
|
||||
}
|
||||
i++;
|
||||
} while (i < entries);
|
||||
if (i >= entries)
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ksz8_add_sta_mac(struct ksz_device *dev, int port,
|
||||
|
||||
@@ -794,5 +794,6 @@
|
||||
#define TAIL_TAG_LOOKUP BIT(7)
|
||||
|
||||
#define FID_ENTRIES 128
|
||||
#define KSZ8_DYN_MAC_ENTRIES 1024
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user