net: dsa: Introduce dsa_is_port_initialized
authorGuenter Roeck <linux@roeck-us.net>
Wed, 25 Feb 2015 07:02:02 +0000 (23:02 -0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 25 Feb 2015 22:57:48 +0000 (17:57 -0500)
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>
include/net/dsa.h
net/dsa/dsa.c
net/dsa/slave.c

index 92be34791963e7e10c3303e906dfb8a5c5cab924..c542c131d5512ae233a98a43468e56a66b5609db 100644 (file)
@@ -165,6 +165,11 @@ static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
        return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
 }
 
+static inline bool dsa_is_port_initialized(struct dsa_switch *ds, int p)
+{
+       return ds->phys_port_mask & (1 << p) && ds->ports[p];
+}
+
 static inline u8 dsa_upstream_port(struct dsa_switch *ds)
 {
        struct dsa_switch_tree *dst = ds->dst;
index 9c208f0dab088958b8dc3fb34d903d84cb9a808f..a1d1f0775bea98df88c1ff1bd775d360393d23fe 100644 (file)
@@ -374,7 +374,7 @@ static int dsa_switch_suspend(struct dsa_switch *ds)
 
        /* Suspend slave network devices */
        for (i = 0; i < DSA_MAX_PORTS; i++) {
-               if (!(ds->phys_port_mask & (1 << i)))
+               if (!dsa_is_port_initialized(ds, i))
                        continue;
 
                ret = dsa_slave_suspend(ds->ports[i]);
@@ -400,7 +400,7 @@ static int dsa_switch_resume(struct dsa_switch *ds)
 
        /* Resume slave network devices */
        for (i = 0; i < DSA_MAX_PORTS; i++) {
-               if (!(ds->phys_port_mask & (1 << i)))
+               if (!dsa_is_port_initialized(ds, i))
                        continue;
 
                ret = dsa_slave_resume(ds->ports[i]);
index b5a4d8974b76e68b380e04011c41b40d7848b654..a47305c72fcc504023db644402b4cf7e285d4cbe 100644 (file)
@@ -222,10 +222,7 @@ static u32 dsa_slave_br_port_mask(struct dsa_switch *ds,
        u32 mask = 0;
 
        for (port = 0; port < DSA_MAX_PORTS; port++) {
-               if (!((1 << port) & ds->phys_port_mask))
-                       continue;
-
-               if (!ds->ports[port])
+               if (!dsa_is_port_initialized(ds, port))
                        continue;
 
                p = netdev_priv(ds->ports[port]);