mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] net: dsa: Introduce dsa_is_port_initialized
@ 2015-02-25  7:02 Guenter Roeck
  2015-02-25 22:58 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2015-02-25  7:02 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Andrew Lunn, Florian Fainelli, linux-kernel,
	Guenter Roeck

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>
---
Applies to net-next on top of Florian's patches adding HW bridging support
to dsa.

 include/net/dsa.h | 5 +++++
 net/dsa/dsa.c     | 4 ++--
 net/dsa/slave.c   | 5 +----
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 92be3479..c542c13 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -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;
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 9c208f0..a1d1f07 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -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]);
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index b5a4d89..a47305c 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,
 	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]);
-- 
2.1.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] net: dsa: Introduce dsa_is_port_initialized
  2015-02-25  7:02 [PATCH net-next] net: dsa: Introduce dsa_is_port_initialized Guenter Roeck
@ 2015-02-25 22:58 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2015-02-25 22:58 UTC (permalink / raw)
  To: linux; +Cc: netdev, andrew, f.fainelli, linux-kernel

From: Guenter Roeck <linux@roeck-us.net>
Date: Tue, 24 Feb 2015 23:02:02 -0800

> 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>

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-02-25 22:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-25  7:02 [PATCH net-next] net: dsa: Introduce dsa_is_port_initialized Guenter Roeck
2015-02-25 22:58 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®