net: dsa: reference count the MDB entries at the cross-chip notifier level
[linux-2.6-microblaze.git] / net / dsa / dsa2.c
index 9000a8c..2035d13 100644 (file)
@@ -348,6 +348,8 @@ static int dsa_port_setup(struct dsa_port *dp)
        if (dp->setup)
                return 0;
 
+       INIT_LIST_HEAD(&dp->mdbs);
+
        switch (dp->type) {
        case DSA_PORT_TYPE_UNUSED:
                dsa_port_disable(dp);
@@ -443,6 +445,7 @@ static int dsa_port_devlink_setup(struct dsa_port *dp)
 static void dsa_port_teardown(struct dsa_port *dp)
 {
        struct devlink_port *dlp = &dp->devlink_port;
+       struct dsa_mac_addr *a, *tmp;
 
        if (!dp->setup)
                return;
@@ -468,6 +471,11 @@ static void dsa_port_teardown(struct dsa_port *dp)
                break;
        }
 
+       list_for_each_entry_safe(a, tmp, &dp->mdbs, list) {
+               list_del(&a->list);
+               kfree(a);
+       }
+
        dp->setup = false;
 }