]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dpaa2-switch: factor out the FDB in-use check into a helper
authorIoana Ciornei <ioana.ciornei@nxp.com>
Wed, 10 Jun 2026 15:09:09 +0000 (18:09 +0300)
committerJakub Kicinski <kuba@kernel.org>
Sun, 14 Jun 2026 00:50:50 +0000 (17:50 -0700)
The dpaa2_switch_port_set_fdb() function is hard to follow and
open-coding the in-use check into it makes it even harder to read.
Factor out that code block into a new helper -
dpaa2_switch_fdb_in_use_by_others().

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Link: https://patch.msgid.link/20260610150912.1788482-3-ioana.ciornei@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c

index 6ac747b4264cd29f7b2036bc6d6aee063f227a18..3052a1c63c2d876bc6633b8cf38b030131e0e70a 100644 (file)
@@ -51,6 +51,22 @@ dpaa2_switch_filter_block_get_unused(struct ethsw_core *ethsw)
        return NULL;
 }
 
+static bool dpaa2_switch_fdb_in_use_by_others(struct ethsw_core *ethsw,
+                                             struct dpaa2_switch_fdb *fdb,
+                                             struct ethsw_port_priv *except)
+{
+       int i;
+
+       for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
+               if (!ethsw->ports[i] || ethsw->ports[i] == except)
+                       continue;
+               if (ethsw->ports[i]->fdb == fdb)
+                       return true;
+       }
+
+       return false;
+}
+
 static void dpaa2_switch_port_set_fdb(struct ethsw_port_priv *port_priv,
                                      struct net_device *upper_dev,
                                      bool linking)
@@ -59,24 +75,13 @@ static void dpaa2_switch_port_set_fdb(struct ethsw_port_priv *port_priv,
        struct ethsw_port_priv *other_port_priv = NULL;
        struct dpaa2_switch_fdb *fdb;
        struct net_device *other_dev;
-       bool last_fdb_user = true;
        struct list_head *iter;
-       int i;
 
        /* If we leave a bridge, find an unused FDB and use that. */
        if (!linking) {
-               /* First verify if this is the last port to leave this bridge */
-               for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
-                       if (!ethsw->ports[i] || ethsw->ports[i] == port_priv)
-                               continue;
-                       if (ethsw->ports[i]->fdb == port_priv->fdb) {
-                               last_fdb_user = false;
-                               break;
-                       }
-               }
-
                /* If this is the last user of the FDB, just keep using it. */
-               if (last_fdb_user) {
+               if (!dpaa2_switch_fdb_in_use_by_others(ethsw, port_priv->fdb,
+                                                      port_priv)) {
                        port_priv->fdb->bridge_dev = NULL;
                        return;
                }