dsa: fix freeing of sparse port allocation
authorFlorian Fainelli <florian@openwrt.org>
Mon, 25 Mar 2013 05:03:40 +0000 (05:03 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 25 Mar 2013 16:23:41 +0000 (12:23 -0400)
If we have defined a sparse port allocation which is non-contiguous and
contains gaps, the code freeing port_names will just stop when it
encouters a first NULL port_names, which is not right, we should iterate
over all possible number of ports (DSA_MAX_PORTS) until we are done.

Signed-off-by: Florian Fainelli <florian@openwrt.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/dsa.c

index aa2ff583b7ed7f4802c5c3bf6541b396b9b1cd3d..0eb5d5e76dfbe1f99537e8a561f1671389c09e16 100644 (file)
@@ -350,9 +350,11 @@ static void dsa_of_free_platform_data(struct dsa_platform_data *pd)
 
        for (i = 0; i < pd->nr_chips; i++) {
                port_index = 0;
-               while (pd->chip[i].port_names &&
-                       pd->chip[i].port_names[++port_index])
-                       kfree(pd->chip[i].port_names[port_index]);
+               while (port_index < DSA_MAX_PORTS) {
+                       if (pd->chip[i].port_names[port_index])
+                               kfree(pd->chip[i].port_names[port_index]);
+                       port_index++;
+               }
                kfree(pd->chip[i].rtable);
        }
        kfree(pd->chip);