Re: [RFC Patch net-next v2 5/9] net: dsa: microchip: move struct mib_names to ksz_chip_data

From: Vladimir Oltean
Date: Mon May 16 2022 - 07:23:54 EST


On Fri, May 13, 2022 at 03:52:15PM +0530, Arun Ramadoss wrote:
> The ksz88xx family has one set of mib_names. The ksz87xx, ksz9477,
> LAN937x based switches has one set of mib_names. In order to remove
> redundant declaration, moved the struct mib_names to ksz_chip_data
> structure. And allocated the mib memory in switch_register instead of
> individual switch_init function.
>
> Signed-off-by: Arun Ramadoss <arun.ramadoss@xxxxxxxxxxxxx>
> ---
> static int ksz9477_switch_init(struct ksz_device *dev)
> {
> - int i;
> -
> dev->ds->ops = &ksz9477_switch_ops;
>
> dev->port_mask = (1 << dev->info->port_cnt) - 1;
>
> - dev->reg_mib_cnt = SWITCH_COUNTER_NUM;
> - dev->mib_cnt = TOTAL_SWITCH_COUNTER_NUM;
> -
> - for (i = 0; i < dev->info->port_cnt; i++) {
> - spin_lock_init(&dev->ports[i].mib.stats64_lock);
> - mutex_init(&dev->ports[i].mib.cnt_mutex);
> - dev->ports[i].mib.counters =
> - devm_kzalloc(dev->dev,
> - sizeof(u64) *
> - (TOTAL_SWITCH_COUNTER_NUM + 1),
> - GFP_KERNEL);
> - if (!dev->ports[i].mib.counters)
> - return -ENOMEM;
> - }
> -

This fixes the NULL pointer dereference on probe that was introduced in
the previous patch, but please make sure that this does not happen in
the first place, for bisectability purposes.

> return 0;
> }