[PATCH net-next v2 3/5] net: dsa: mt7530: register the GPIO controller last in setup

From: Haoran Wang

Date: Thu Dec 03 2026 - 01:49:22 EST


mt7530_setup_gpio() publishes a GPIO controller that userspace and other
drivers can use immediately, but it currently runs before the FDB flush,
the last fallible step of mt7530_setup().

Move the GPIO controller registration after the FDB flush so that the
controller is not published when mt7530_setup() fails. This matters from
the next patch on, where a failed mt7530_setup() disables the regulators
and returns an error, and the controller must not be registered across a
failed setup.

Signed-off-by: Haoran Wang <wanghr2026@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Andrew Lunn <andrew@xxxxxxx>
---
drivers/net/dsa/mt7530.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 17c62b53ca06..e784123fb79c 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -2594,6 +2594,11 @@ mt7530_setup(struct dsa_switch *ds)
}
}

+ /* Flush the FDB table */
+ ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
+ if (ret < 0)
+ return ret;
+
#ifdef CONFIG_GPIOLIB
if (of_property_read_bool(priv->dev->of_node, "gpio-controller")) {
ret = mt7530_setup_gpio(priv);
@@ -2602,11 +2607,6 @@ mt7530_setup(struct dsa_switch *ds)
}
#endif /* CONFIG_GPIOLIB */

- /* Flush the FDB table */
- ret = mt7530_fdb_cmd(priv, MT7530_FDB_FLUSH, NULL);
- if (ret < 0)
- return ret;
-
return 0;
}