Re: [RFC net] net: dsa: Add missing reference counting

From: Andrew Lunn
Date: Thu May 07 2020 - 09:03:00 EST


On Wed, May 06, 2020 at 02:24:14PM -0700, Florian Fainelli wrote:
>
>
> On 5/5/2020 2:23 PM, Vivien Didelot wrote:
> > On Tue, 5 May 2020 14:02:53 -0700, Florian Fainelli <f.fainelli@xxxxxxxxx> wrote:
> >> If we are probed through platform_data we would be intentionally
> >> dropping the reference count on master after dev_to_net_device()
> >> incremented it. If we are probed through Device Tree,
> >> of_find_net_device() does not do a dev_hold() at all.
> >>
> >> Ensure that the DSA master device is properly reference counted by
> >> holding it as soon as the CPU port is successfully initialized and later
> >> released during dsa_switch_release_ports(). dsa_get_tag_protocol() does
> >> a short de-reference, so we hold and release the master at that time,
> >> too.
> >>
> >> Fixes: 83c0afaec7b7 ("net: dsa: Add new binding implementation")
> >> Signed-off-by: Florian Fainelli <f.fainelli@xxxxxxxxx>
> >
> > Reviewed-by: Vivien Didelot <vivien.didelot@xxxxxxxxx>
> >
> Andrew, Vladimir, any thoughts on that?

Hi Florian

Have you looked at how other stacked drivers do this? bond/team, vlan,
bridge, BATMAN?

Do we maybe need to subscribe to the master devices notifier chain,
and do a tear down when the device is removed?

Andrew