🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
5 messages
5 total messages Started by David Yang Fri, 27 Nov 2026 07:03
[PATCH net-next v2] net: dsa: motorcomm: Unregister the MDIO buses on teardown
#23383
Author: David Yang
Date: Fri, 27 Nov 2026 07:03
186 lines
15574 bytes
.setup() can run again within one registration: removing another switch
from the tree tears the whole tree down, and re-probing sets every
member switch up again.

Since our MDIO buses are registered in .setup() and not released in
.teardown(), the second registration then collides with the bus that is
still registered (same name under the same parent) and fails in
__mdiobus_register(), so the whole tree setup fails.

Register the buses manually and free them in .teardown().

Not carrying a fix tag since there are no multi-chip yt921x users.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c     | 24 +++++++++++++++----
 drivers/net/dsa/motorcomm/mdio_bus.c | 36 +++++++++++++++++++++++-----
 drivers/net/dsa/motorcomm/mdio_bus.h |  2 ++
 3 files changed, 51 insertions(+), 11 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index a21d4bb5e141..82f364986aeb 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -2240,13 +2240,18 @@ static int yt921x_edata_read(struct yt921x_priv *priv, u8 addr, u8 *valp)
 
 static void yt921x_dsa_teardown(struct dsa_switch *ds)
 {
-#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
 	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
 
+#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
 	yt921x_leds_remove(priv);
 #endif
 
 	dsa_devlink_resources_unregister(ds);
+
+	if (priv->mbus_ext)
+		yt921x_mbus_ext_cleanup(priv);
+	if (priv->mbus_int)
+		yt921x_mbus_int_cleanup(priv);
 }
 
 static int yt921x_chip_detect(struct yt921x_priv *priv)
@@ -2558,10 +2563,11 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)
 		res = yt921x_mbus_ext_init(priv, child);
 		of_node_put(child);
 		if (res)
-			return res;
+			goto err_mbus_int;
 
 		dev_err(dev, "Untested external mdio bus\n");
-		return -ENODEV;
+		res = -ENODEV;
+		goto err;
 	}
 
 	mask = priv->info->serdes_mask;
@@ -2586,11 +2592,11 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)
 	mutex_unlock(&priv->reg_lock);
 
 	if (res)
-		return res;
+		goto err;
 
 	res = yt921x_devlink_setup(priv);
 	if (res)
-		return res;
+		goto err;
 
 #if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
 	res = yt921x_leds_setup(priv);
@@ -2599,6 +2605,14 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)
 #endif
 
 	return 0;
+
+err:
+	if (priv->mbus_ext)
+		yt921x_mbus_ext_cleanup(priv);
+err_mbus_int:
+	if (priv->mbus_int)
+		yt921x_mbus_int_cleanup(priv);
+	return res;
 }
 
 static const struct phylink_mac_ops yt921x_phylink_mac_ops = {
diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c
index dd6c52f37bbf..a4062e6b0f00 100644
--- a/drivers/net/dsa/motorcomm/mdio_bus.c
+++ b/drivers/net/dsa/motorcomm/mdio_bus.c
@@ -141,13 +141,23 @@ yt921x_mbus_int_write(struct mii_bus *mbus, int port, int reg, u16 data)
 	return res;
 }
 
+void yt921x_mbus_int_cleanup(struct yt921x_priv *priv)
+{
+	struct mii_bus *mbus = priv->mbus_int;
+
+	priv->mbus_int = NULL;
+
+	mdiobus_unregister(mbus);
+	mdiobus_free(mbus);
+}
+
 int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
 {
 	struct device *dev = yt921x_priv_to_device(priv);
 	struct mii_bus *mbus;
 	int res;
 
-	mbus = devm_mdiobus_alloc(dev);
+	mbus = mdiobus_alloc();
 	if (!mbus)
 		return -ENOMEM;
 
@@ -159,9 +169,11 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
 	mbus->parent = dev;
 	mbus->phy_mask = (u32)~GENMASK(YT921X_PORT_NUM - 1, 0);
 
-	res = devm_of_mdiobus_register(dev, mbus, mnp);
-	if (res)
+	res = of_mdiobus_register(mbus, mnp);
+	if (res) {
+		mdiobus_free(mbus);
 		return res;
+	}
 
 	priv->mbus_int = mbus;
 
@@ -271,13 +283,23 @@ yt921x_mbus_ext_write(struct mii_bus *mbus, int port, int reg, u16 data)
 	return res;
 }
 
+void yt921x_mbus_ext_cleanup(struct yt921x_priv *priv)
+{
+	struct mii_bus *mbus = priv->mbus_ext;
+
+	priv->mbus_ext = NULL;
+
+	mdiobus_unregister(mbus);
+	mdiobus_free(mbus);
+}
+
 int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp)
 {
 	struct device *dev = yt921x_priv_to_device(priv);
 	struct mii_bus *mbus;
 	int res;
 
-	mbus = devm_mdiobus_alloc(dev);
+	mbus = mdiobus_alloc();
 	if (!mbus)
 		return -ENOMEM;
 
@@ -289,9 +311,11 @@ int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp)
 	mbus->write = yt921x_mbus_ext_write;
 	mbus->parent = dev;
 
-	res = devm_of_mdiobus_register(dev, mbus, mnp);
-	if (res)
+	res = of_mdiobus_register(mbus, mnp);
+	if (res) {
+		mdiobus_free(mbus);
 		return res;
+	}
 
 	priv->mbus_ext = mbus;
 
diff --git a/drivers/net/dsa/motorcomm/mdio_bus.h b/drivers/net/dsa/motorcomm/mdio_bus.h
index e79b725d435b..603088b5b8f4 100644
--- a/drivers/net/dsa/motorcomm/mdio_bus.h
+++ b/drivers/net/dsa/motorcomm/mdio_bus.h
@@ -48,7 +48,9 @@ yt921x_intif_modify(struct yt921x_priv *priv, int port, int reg, u16 mask,
 	return res >= 0 ? 0 : res;
 }
 
+void yt921x_mbus_int_cleanup(struct yt921x_priv *priv);
 int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp);
+void yt921x_mbus_ext_cleanup(struct yt921x_priv *priv);
 int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp);
 
 #endif
-- 
2.53.0
Re: [PATCH net-next v2] net: dsa: motorcomm: Unregister the MDIO buses on teardown
#23385
Author: netdev-bot+sinfo
Date: Fri, 27 Nov 2026 07:07
23 lines
8708 bytes
Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
Re: [PATCH net-next v2] net: dsa: motorcomm: Unregister the MDIO buses on teardown
#23388
Author: David Yang
Date: Fri, 27 Nov 2026 07:17
34 lines
13151 bytes
On Fri, Nov 27, 2026 at 3:07 PM <netdev-bot+sinfo@kernel.org> wrote:
>
> Hi!
>
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
>
>  - How the issue was discovered, e.g. hit in production, hit during
>    development, syzbot report, manual code inspection, LLM or static
>    analysis tool scan.
>
>  - Whether the issue was actually triggered, or is only theoretical
>    (e.g. found by LLM and not proven at runtime). If it was triggered
>    please include the symptoms, like the stack trace or kernel messages.
>
> Please do not repost the series just to address the above. Instead,
> reply to this email with the missing information, so that reviewers
> can take it into account.
>
> *IMPORTANT*: If you do repost (for other reasons) - please include
> the relevant info in the cover letter or commit messages.
> --
> The evaluation is done by an LLM so it may be wrong, if you think
> that is the case please reply and explain.

Not a fix, explained in the message.

Sorry, I missed the changelog:

v1: https://lore.kernel.org/r/20261126034725.64709-1-mmyangfl@gmail.com
- fix err path for yt921x_devlink_setup
- make NULL checks explict
Re: [PATCH net-next v2] net: dsa: motorcomm: Unregister the MDIO buses on teardown
#23582
Author: Andrew Lunn
Date: Fri, 27 Nov 2026 14:39
20 lines
8914 bytes
On Fri, Nov 27, 2026 at 03:03:52PM +0800, David Yang wrote:
> .setup() can run again within one registration: removing another switch
> from the tree tears the whole tree down, and re-probing sets every
> member switch up again.
> 
> Since our MDIO buses are registered in .setup() and not released in
> .teardown(), the second registration then collides with the bus that is
> still registered (same name under the same parent) and fails in
> __mdiobus_register(), so the whole tree setup fails.
> 
> Register the buses manually and free them in .teardown().
> 
> Not carrying a fix tag since there are no multi-chip yt921x users.
> 
> Signed-off-by: David Yang <mmyangfl@gmail.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Re: [PATCH net-next v2] net: dsa: motorcomm: Unregister the MDIO buses on teardown
#25590
Author: patchwork-bot+netdevbpf
Date: Wed, 02 Dec 2026 03:10
26 lines
8764 bytes
Hello:

This patch was applied to netdev/net-next.git (main)
by Willem de Bruijn <willemb@google.com>:

On Fri, 27 Nov 2026 15:03:52 +0800 you wrote:
> .setup() can run again within one registration: removing another switch
> from the tree tears the whole tree down, and re-probing sets every
> member switch up again.
> 
> Since our MDIO buses are registered in .setup() and not released in
> .teardown(), the second registration then collides with the bus that is
> still registered (same name under the same parent) and fails in
> __mdiobus_register(), so the whole tree setup fails.
> 
> [...]

Here is the summary with links:
  - [net-next,v2] net: dsa: motorcomm: Unregister the MDIO buses on teardown
    https://git.kernel.org/netdev/net-next/c/ade920327468

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads