From: Florian Fainelli Date: Sun, 12 Jul 2015 01:02:10 +0000 (-0700) Subject: net: dsa: Test array index before use X-Git-Tag: v3.16.35~1592 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a72eb546da6f95d5043f4731f8e9ae7476f14322;p=thirdparty%2Fkernel%2Fstable.git net: dsa: Test array index before use commit 8f5063e97f393d49611151d3cf7dcbeb41397f12 upstream. 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 Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Luis Henriques --- diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 5db37cef50a9c..d3ca32dc167f2 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -427,6 +427,8 @@ static int dsa_of_probe(struct platform_device *pdev) 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) @@ -449,8 +451,6 @@ static int dsa_of_probe(struct platform_device *pdev) goto out_free_chip; } - if (port_index == DSA_MAX_PORTS) - break; } }