Skip to content

Commit

Permalink
net: dsa: Test array index before use
Browse files Browse the repository at this point in the history
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: 5e95329: ("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>
  • Loading branch information
Florian Fainelli authored and David S. Miller committed Jul 12, 2015
1 parent 2ee9401 commit 8f5063e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/dsa/dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -666,8 +668,6 @@ static int dsa_of_probe(struct device *dev)
goto out_free_chip;
}

if (port_index == DSA_MAX_PORTS)
break;
}
}

Expand Down

0 comments on commit 8f5063e

Please sign in to comment.