Skip to content

Commit 02319bf

Browse files
ffainellidavem330
authored andcommitted
net: dsa: bcm_sf2: Fix array overrun in bcm_sf2_num_active_ports()
After d12e1c4 ("net: dsa: b53: Set correct number of ports in the DSA struct") we stopped setting dsa_switch::num_ports to DSA_MAX_PORTS, which created an off by one error between the statically allocated bcm_sf2_priv::port_sts array (of size DSA_MAX_PORTS). When dsa_is_cpu_port() is used, we end-up accessing an out of bounds member and causing a NPD. Fix this by iterating with the appropriate port count using ds->num_ports. Fixes: d12e1c4 ("net: dsa: b53: Set correct number of ports in the DSA struct") Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3c9cfb5 commit 02319bf

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/net/dsa/bcm_sf2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static unsigned int bcm_sf2_num_active_ports(struct dsa_switch *ds)
6868
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
6969
unsigned int port, count = 0;
7070

71-
for (port = 0; port < ARRAY_SIZE(priv->port_sts); port++) {
71+
for (port = 0; port < ds->num_ports; port++) {
7272
if (dsa_is_cpu_port(ds, port))
7373
continue;
7474
if (priv->port_sts[port].enabled)

0 commit comments

Comments
 (0)