• Vivien Didelot's avatar
    net: dsa: simplify tree reference counting · 8e5bf975
    Vivien Didelot authored
    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: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
    Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    8e5bf975
dsa2.c 16.4 KB