]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net: dsa: Test array index before use
authorFlorian Fainelli <f.fainelli@gmail.com>
Sun, 12 Jul 2015 01:02:10 +0000 (18:02 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sun, 12 Jul 2015 06:25:16 +0000 (23:25 -0700)
port_index is used an index into an array, and this information comes
from Device Tree, make sure that port_index is not equal to the array
size before using it. Move the check against port_index earlier in the
loop.

Fixes: 5e95329b701c: ("dsa: add device tree bindings to register DSA switches")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/dsa.c

index 392e29a0227dbf4aa4870d73c5ef333db528b675..52beeb8829dc55fbf73785e851fc2da1b5b58fac 100644 (file)
@@ -642,6 +642,8 @@ static int dsa_of_probe(struct device *dev)
                                continue;
 
                        port_index = be32_to_cpup(port_reg);
+                       if (port_index >= DSA_MAX_PORTS)
+                               break;
 
                        port_name = of_get_property(port, "label", NULL);
                        if (!port_name)
@@ -666,8 +668,6 @@ static int dsa_of_probe(struct device *dev)
                                        goto out_free_chip;
                        }
 
-                       if (port_index == DSA_MAX_PORTS)
-                               break;
                }
        }