thunderbolt: Add helper macro to iterate over switch ports

There are quite many places in the driver where we iterate over each
port in the switch. To make it bit more convenient, add a macro that can
be used to iterate over each port and convert existing call sites to use it.

This is based on code by Lukas Wunner.

No functional changes.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Cette révision appartient à :
Mika Westerberg
2019-09-30 14:07:22 +03:00
Parent 826c6a1773
révision b433d01005
5 fichiers modifiés avec 74 ajouts et 65 suppressions

Voir le fichier

@@ -530,6 +530,17 @@ struct tb_switch *tb_switch_find_by_link_depth(struct tb *tb, u8 link,
struct tb_switch *tb_switch_find_by_uuid(struct tb *tb, const uuid_t *uuid);
struct tb_switch *tb_switch_find_by_route(struct tb *tb, u64 route);
/**
* tb_switch_for_each_port() - Iterate over each switch port
* @sw: Switch whose ports to iterate
* @p: Port used as iterator
*
* Iterates over each switch port skipping the control port (port %0).
*/
#define tb_switch_for_each_port(sw, p) \
for ((p) = &(sw)->ports[1]; \
(p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++)
static inline struct tb_switch *tb_switch_get(struct tb_switch *sw)
{
if (sw)