OSDN Git Service

net: dsa: simplify tree reference counting
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>
Fri, 3 Nov 2017 23:05:22 +0000 (19:05 -0400)
committerDavid S. Miller <davem@davemloft.net>
Sun, 5 Nov 2017 13:31:38 +0000 (22:31 +0900)
commit8e5bf9759a06be2251fa96cfd8b412f1808c62f9
treeb328e0e1df8dd864946ef0a17f5b25310fa4f3cd
parent49463b7f2da1a115404b02c5533bc2c2125833a3
net: dsa: simplify tree reference counting

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@savoirfairelinux.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/dsa2.c