Re: [PATCH net-next v4 4/4] net: ocelot: add FDMA support

From: Vladimir Oltean
Date: Sat Dec 04 2021 - 06:52:16 EST


On Sat, Dec 04, 2021 at 07:52:06AM +0100, Clément Léger wrote:
> > +void ocelot_fdma_netdev_init(struct ocelot *ocelot, struct net_device *dev)
> > +{
> > + struct ocelot_fdma *fdma = ocelot->fdma;
> > +
> > + dev->needed_headroom = OCELOT_TAG_LEN;
> > + dev->needed_tailroom = ETH_FCS_LEN;
> > +
> > + if (fdma->napi_init)
> > + return;
> > +
> > + fdma->napi_init = true;
> > + netif_napi_add(dev, &ocelot->napi, ocelot_fdma_napi_poll,
> > + OCELOT_FDMA_WEIGHT);
> > +}
> > +
> > +void ocelot_fdma_netdev_deinit(struct ocelot *ocelot, struct net_device *dev)
> > +{
> > + struct ocelot_fdma *fdma = ocelot->fdma;
> > +
> > + if (fdma->napi_init) {
> > + netif_napi_del(&ocelot->napi);
> > + fdma->napi_init = false;
> > + }
>
> Using a boolean is acutally a bad idea, if the last netdev
> registration fails in ocelot, then the napi context will be deleted.
> The net_device should actually be used.

I think that you could try to call netif_napi_del() only if dev == napi->dev.
Because, as you say, if the NAPI structure has been added to the first
net device, and the registration of subsequent net devices fails, that
NAPI might actually even be in use by now, we should not disturb it.