Skip to content

Commit 8f5063e

Browse files
ffainellidavem330
authored andcommitted
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: 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>
1 parent 2ee9401 commit 8f5063e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/dsa/dsa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,8 @@ static int dsa_of_probe(struct device *dev)
642642
continue;
643643

644644
port_index = be32_to_cpup(port_reg);
645+
if (port_index >= DSA_MAX_PORTS)
646+
break;
645647

646648
port_name = of_get_property(port, "label", NULL);
647649
if (!port_name)
@@ -666,8 +668,6 @@ static int dsa_of_probe(struct device *dev)
666668
goto out_free_chip;
667669
}
668670

669-
if (port_index == DSA_MAX_PORTS)
670-
break;
671671
}
672672
}
673673

0 commit comments

Comments
 (0)