aboutsummaryrefslogtreecommitdiffstats
path: root/net/dsa
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2015-02-25 02:02:02 -0500
committerDavid S. Miller <davem@davemloft.net>2015-02-25 17:57:48 -0500
commitd79d21073626cf022943e5c4c10a97cdf7cb8465 (patch)
tree529fa340e3b007cce36bb7665f1eef4807bdb5b4 /net/dsa
parentbb66be1c549a0760500cfad404b3d79a136d0e44 (diff)
net: dsa: Introduce dsa_is_port_initialized
To avoid race conditions when using the ds->ports[] array, we need to check if the accessed port has been initialized. Introduce and use helper function dsa_is_port_initialized for that purpose and use it where needed. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa')
-rw-r--r--net/dsa/dsa.c4
-rw-r--r--net/dsa/slave.c5
2 files changed, 3 insertions, 6 deletions
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 9c208f0dab08..a1d1f0775bea 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -374,7 +374,7 @@ static int dsa_switch_suspend(struct dsa_switch *ds)
374 374
375 /* Suspend slave network devices */ 375 /* Suspend slave network devices */
376 for (i = 0; i < DSA_MAX_PORTS; i++) { 376 for (i = 0; i < DSA_MAX_PORTS; i++) {
377 if (!(ds->phys_port_mask & (1 << i))) 377 if (!dsa_is_port_initialized(ds, i))
378 continue; 378 continue;
379 379
380 ret = dsa_slave_suspend(ds->ports[i]); 380 ret = dsa_slave_suspend(ds->ports[i]);
@@ -400,7 +400,7 @@ static int dsa_switch_resume(struct dsa_switch *ds)
400 400
401 /* Resume slave network devices */ 401 /* Resume slave network devices */
402 for (i = 0; i < DSA_MAX_PORTS; i++) { 402 for (i = 0; i < DSA_MAX_PORTS; i++) {
403 if (!(ds->phys_port_mask & (1 << i))) 403 if (!dsa_is_port_initialized(ds, i))
404 continue; 404 continue;
405 405
406 ret = dsa_slave_resume(ds->ports[i]); 406 ret = dsa_slave_resume(ds->ports[i]);
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index b5a4d8974b76..a47305c72fcc 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -222,10 +222,7 @@ static u32 dsa_slave_br_port_mask(struct dsa_switch *ds,
222 u32 mask = 0; 222 u32 mask = 0;
223 223
224 for (port = 0; port < DSA_MAX_PORTS; port++) { 224 for (port = 0; port < DSA_MAX_PORTS; port++) {
225 if (!((1 << port) & ds->phys_port_mask)) 225 if (!dsa_is_port_initialized(ds, port))
226 continue;
227
228 if (!ds->ports[port])
229 continue; 226 continue;
230 227
231 p = netdev_priv(ds->ports[port]); 228 p = netdev_priv(ds->ports[port]);