Re: [PATCH net-next 03/11] net: dsa: simplify tree reference counting

From: Florian Fainelli
Date: Fri Nov 03 2017 - 19:16:20 EST


On 11/03/2017 04:05 PM, Vivien Didelot wrote:
> DSA trees have a refcount used to automatically free the dsa_switch_tree
> structure once there is no switch devices inside of it.
>
> The refcount is incremented when a switch is added to the tree, and
> decremented when it is removed from it.
>
> But because of kref_init, the refcount is also incremented at
> initialization, and when looking up the tree from the list for symmetry.
>
> Thus the current code stores the number of switches plus one, and makes
> the switch registration more complex.
>
> To simplify the switch registration function, we reset the refcount to
> zero after initialization and don't increment it when looking up a tree.
>
> Signed-off-by: Vivien Didelot <vivien.didelot@xxxxxxxxxxxxxxxxxxxx>

Reviewed-by: Florian Fainelli <f.fainelli@xxxxxxxxx>
--
Florian