]> git.baikalelectronics.ru Git - kernel.git/commit
net: dsa: remove the "dsa_to_port in a loop" antipattern from the core
authorVladimir Oltean <vladimir.oltean@nxp.com>
Wed, 20 Oct 2021 17:49:50 +0000 (20:49 +0300)
committerDavid S. Miller <davem@davemloft.net>
Thu, 21 Oct 2021 11:44:06 +0000 (12:44 +0100)
commit167aaa473955ce225fa932906d200540ab3aaa50
tree03811eb15c15b4bec1430485f0a94b38535629e6
parent19a6298b389690f6f45237051545917ea3bc7f64
net: dsa: remove the "dsa_to_port in a loop" antipattern from the core

Ever since Vivien's conversion of the ds->ports array into a dst->ports
list, and the introduction of dsa_to_port, iterations through the ports
of a switch became quadratic whenever dsa_to_port was needed.

dsa_to_port can either be called directly, or indirectly through the
dsa_is_{user,cpu,dsa,unused}_port helpers.

Use the newly introduced dsa_switch_for_each_port() iteration macro
that works with the iterator variable being a struct dsa_port *dp
directly, and not an int i. It is an expensive variable to go from i to
dp, but cheap to go from dp to i.

This macro iterates through the entire ds->dst->ports list and filters
by the ports belonging just to the switch provided as argument.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/dsa.h
net/dsa/dsa.c
net/dsa/dsa2.c
net/dsa/port.c
net/dsa/slave.c
net/dsa/switch.c