Re: [PATCH v1 10/26] net: dsa: microchip: ksz8: refactor ksz8_fdb_dump()

From: Oleksij Rempel
Date: Tue Nov 29 2022 - 03:51:19 EST


On Tue, Nov 29, 2022 at 08:29:47AM +0000, Arun.Ramadoss@xxxxxxxxxxxxx wrote:
> Hi Oleksij,
>
> On Mon, 2022-11-28 at 12:59 +0100, Oleksij Rempel wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you
> > know the content is safe
> >
> > After fixing different bugs we can refactor this function:
> > - be paranoid - read only max possibly amount of entries supported by
> > the HW.
> > - pass error values returned by regmap
> >
> > Signed-off-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
> > ---
> > drivers/net/dsa/microchip/ksz8795.c | 41 ++++++++++++++---------
> > --
> > drivers/net/dsa/microchip/ksz8795_reg.h | 1 +
> > 2 files changed, 24 insertions(+), 18 deletions(-)
> >
> > diff --git a/drivers/net/dsa/microchip/ksz8795.c
> > b/drivers/net/dsa/microchip/ksz8795.c
> > index 736cf4e54333..308b46bb2ce5 100644
> > --- a/drivers/net/dsa/microchip/ksz8795.c
> > +++ b/drivers/net/dsa/microchip/ksz8795.c
> > @@ -949,26 +949,31 @@ 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 src_port;
> > - u8 mac[ETH_ALEN];
> > + u16 i, entries = 0;
> > + int ret;
> >
> > - do {
> > - ret = ksz8_r_dyn_mac_table(dev, i, mac, &src_port,
> > - &entries);
> > - if (!ret && port == src_port) {
> > - ret = cb(mac, 0, false, data);
> > - if (ret)
> > - break;
> > - }
> > - i++;
> > - } while (i < entries);
> > - if (i >= entries)
> > - ret = 0;
> > + for (i = 0; i < KSZ8_DYN_MAC_ENTRIES; i++) {
> > + u8 mac[ETH_ALEN];
> > + u8 src_port;
>
> Any specific reason for declaring variable within for loop instead of
> outside.

No. It is personal preference to declare variables within the scope where
variable is used.

--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |