diff options
author | Florian Fainelli <f.fainelli@gmail.com> | 2015-07-11 18:02:10 -0700 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-07-11 23:25:16 -0700 |
commit | 8f5063e97f393d49611151d3cf7dcbeb41397f12 (patch) | |
tree | 09864acdea8b4c1ef6ed6a9d4f0b159f25d9ef28 /net/dsa/dsa.c | |
parent | 2ee94014d9bd3868b1c0d17405f96d63bec83f28 (diff) | |
download | linux-stable-8f5063e97f393d49611151d3cf7dcbeb41397f12.tar.gz linux-stable-8f5063e97f393d49611151d3cf7dcbeb41397f12.tar.bz2 linux-stable-8f5063e97f393d49611151d3cf7dcbeb41397f12.zip |
net: dsa: Test array index before use
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>
Diffstat (limited to 'net/dsa/dsa.c')
-rw-r--r-- | net/dsa/dsa.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 392e29a0227d..52beeb8829dc 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -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; } } |