Commit 7b9a2f4b authored by Vivien Didelot's avatar Vivien Didelot Committed by Jakub Kicinski
Browse files

net: dsa: use ports list to find slave



Use the new ports list instead of iterating over switches and their
ports when looking for a slave device from a given master interface.

Signed-off-by: default avatarVivien Didelot <vivien.didelot@gmail.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
parent b96ddf25
Loading
Loading
Loading
Loading
+6 −17
Original line number Diff line number Diff line
@@ -104,25 +104,14 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
{
	struct dsa_port *cpu_dp = dev->dsa_ptr;
	struct dsa_switch_tree *dst = cpu_dp->dst;
	struct dsa_switch *ds;
	struct dsa_port *slave_port;

	if (device < 0 || device >= DSA_MAX_SWITCHES)
		return NULL;

	ds = dst->ds[device];
	if (!ds)
		return NULL;

	if (port < 0 || port >= ds->num_ports)
		return NULL;
	struct dsa_port *dp;

	slave_port = &ds->ports[port];
	list_for_each_entry(dp, &dst->ports, list)
		if (dp->ds->index == device && dp->index == port &&
		    dp->type == DSA_PORT_TYPE_USER)
			return dp->slave;

	if (unlikely(slave_port->type != DSA_PORT_TYPE_USER))
	return NULL;

	return slave_port->slave;
}

/* port.c */