Re: [PATCH net 6/8] net: mscc: ocelot: make struct ocelot_stat_layout array indexable

Colin Foster
2022-08-17T22:07:57Z

On Wed, Aug 17, 2022 at 10:03:51PM +0000, Vladimir Oltean wrote:
> On Wed, Aug 17, 2022 at 01:47:07PM -0700, Colin Foster wrote:
> > > How about we add this extra check?
> > >
> > > diff --git a/drivers/net/ethernet/mscc/ocelot_stats.c b/drivers/net/ethernet/mscc/ocelot_stats.c
> > > index d39908c1c6c9..85259de86ec2 100644
> > > --- a/drivers/net/ethernet/mscc/ocelot_stats.c
> > > +++ b/drivers/net/ethernet/mscc/ocelot_stats.c
> > > @@ -385,7 +385,7 @@ EXPORT_SYMBOL(ocelot_port_get_stats64);
> > > static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
> > > {
> > > struct ocelot_stats_region *region = NULL;
> > > - unsigned int last;
> > > + unsigned int last = 0;
> > > int i;
> > >
> > > INIT_LIST_HEAD(&ocelot->stats_regions);
> > > @@ -402,6 +402,12 @@ static int ocelot_prepare_stats_regions(struct ocelot *ocelot)
> > > if (!region)
> > > return -ENOMEM;
> > >
> > > + /* enum ocelot_stat must be kept sorted in the same
> > > + * order as ocelot->stats_layout[i].reg in order to
> > > + * have efficient bulking.
> > > + */
> > > + WARN_ON(last >= ocelot->stats_layout[i].reg);
> > > +
> > > region->base = ocelot->stats_layout[i].reg;
> > > region->count = 1;
> > > list_add_tail(&region->node, &ocelot->stats_regions);
> > >
> > > If not, help me understand the concern better.
> >
> > You get my concern. That's a good comment / addition. Gaps are welcome
> > in the register layout, but moving backwards will ensure (in the current
> > implementation) inefficiencies.
>
> Ok. The WARN_ON() won't trigger with current code. Do you mind if I add
> it as a net-next change, and don't resend this series for net? I'm
> worried I'll miss this week's "net" pull request which means I'll have
> to wait some more for the other rework surrounding stats handling in the
> ocelot driver (which in turn is a dependency for frame preemption).

No objections here.

I'll respond in more detail to your other points in a separate email.
Might not be able to craft a response today.