diff mbox series

[RFC,net-next,1/4] net: dsa: introduce a dsa_port_is_unused helper

Message ID 20210809190320.1058373-2-vladimir.oltean@nxp.com
State Superseded
Headers show
Series Remove the "dsa_to_port in a loop" antipattern | expand

Commit Message

Vladimir Oltean Aug. 9, 2021, 7:03 p.m. UTC
Similar to the existing dsa_port_is_{cpu,user,dsa} helpers which operate
directly on a struct dsa_port *dp, let's introduce the equivalent of
dsa_is_unused_port. We will use this to create a more efficient iterator
over the available ports of a switch.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 include/net/dsa.h | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Florian Fainelli Aug. 10, 2021, 9:34 a.m. UTC | #1
On 8/9/2021 12:03 PM, Vladimir Oltean wrote:
> Similar to the existing dsa_port_is_{cpu,user,dsa} helpers which operate

> directly on a struct dsa_port *dp, let's introduce the equivalent of

> dsa_is_unused_port. We will use this to create a more efficient iterator

> over the available ports of a switch.

> 

> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>


Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

-- 
Florian
diff mbox series

Patch

diff --git a/include/net/dsa.h b/include/net/dsa.h
index cd7dc74d0d4c..d05c71a92715 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -431,6 +431,11 @@  static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
 	return NULL;
 }
 
+static inline bool dsa_port_is_unused(struct dsa_port *port)
+{
+	return port->type == DSA_PORT_TYPE_UNUSED;
+}
+
 static inline bool dsa_port_is_dsa(struct dsa_port *port)
 {
 	return port->type == DSA_PORT_TYPE_DSA;