Thread View: linux.kernel.netdev
6 messages
6 total messages
Started by David Yang
Thu, 26 Nov 2026 03:47
[PATCH net-next] net: dsa: motorcomm: Unregister the MDIO buses on teardown
Author: David Yang
Date: Thu, 26 Nov 2026 03:47
Date: Thu, 26 Nov 2026 03:47
176 lines
15283 bytes
15283 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 known multi-chip yt921x users.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
drivers/net/dsa/motorcomm/chip.c | 18 ++++++++++---
drivers/net/dsa/motorcomm/mdio_bus.c | 40 +++++++++++++++++++++++-----
drivers/net/dsa/motorcomm/mdio_bus.h | 2 ++
3 files changed, 50 insertions(+), 10 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index a21d4bb5e141..789a08dbe3b9 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -2240,13 +2240,16 @@ 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);
+
+ yt921x_mbus_ext_remove(priv);
+ yt921x_mbus_int_remove(priv);
}
static int yt921x_chip_detect(struct yt921x_priv *priv)
@@ -2558,10 +2561,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,7 +2590,7 @@ 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)
@@ -2599,6 +2603,12 @@ static int yt921x_dsa_setup(struct dsa_switch *ds)
#endif
return 0;
+
+err:
+ yt921x_mbus_ext_remove(priv);
+err_mbus_int:
+ yt921x_mbus_int_remove(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..3aea4fd3102e 100644
--- a/drivers/net/dsa/motorcomm/mdio_bus.c
+++ b/drivers/net/dsa/motorcomm/mdio_bus.c
@@ -147,7 +147,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp)
struct mii_bus *mbus;
int res;
- mbus = devm_mdiobus_alloc(dev);
+ mbus = mdiobus_alloc();
if (!mbus)
return -ENOMEM;
@@ -159,15 +159,29 @@ 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;
return 0;
}
+void yt921x_mbus_int_remove(struct yt921x_priv *priv)
+{
+ struct mii_bus *mbus = priv->mbus_int;
+
+ if (!mbus)
+ return;
+ priv->mbus_int = NULL;
+
+ mdiobus_unregister(mbus);
+ mdiobus_free(mbus);
+}
+
static int yt921x_extif_wait(struct yt921x_priv *priv)
{
u32 val = 0;
@@ -277,7 +291,7 @@ int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp)
struct mii_bus *mbus;
int res;
- mbus = devm_mdiobus_alloc(dev);
+ mbus = mdiobus_alloc();
if (!mbus)
return -ENOMEM;
@@ -289,11 +303,25 @@ 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;
return 0;
}
+
+void yt921x_mbus_ext_remove(struct yt921x_priv *priv)
+{
+ struct mii_bus *mbus = priv->mbus_ext;
+
+ if (!mbus)
+ return;
+ priv->mbus_ext = NULL;
+
+ mdiobus_unregister(mbus);
+ mdiobus_free(mbus);
+}
diff --git a/drivers/net/dsa/motorcomm/mdio_bus.h b/drivers/net/dsa/motorcomm/mdio_bus.h
index e79b725d435b..9cb1824714e3 100644
--- a/drivers/net/dsa/motorcomm/mdio_bus.h
+++ b/drivers/net/dsa/motorcomm/mdio_bus.h
@@ -49,6 +49,8 @@ yt921x_intif_modify(struct yt921x_priv *priv, int port, int reg, u16 mask,
}
int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp);
+void yt921x_mbus_int_remove(struct yt921x_priv *priv);
int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp);
+void yt921x_mbus_ext_remove(struct yt921x_priv *priv);
#endif
--
2.53.0
Re: [PATCH net-next] net: dsa: motorcomm: Unregister the MDIO buses on teardown
Author: netdev-bot+sinfo
Date: Thu, 26 Nov 2026 03:52
Date: Thu, 26 Nov 2026 03:52
23 lines
8686 bytes
8686 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] net: dsa: motorcomm: Unregister the MDIO buses on teardown
Author: David Yang
Date: Thu, 26 Nov 2026 04:00
Date: Thu, 26 Nov 2026 04:00
28 lines
12980 bytes
12980 bytes
On Thu, Nov 26, 2026 at 11:52 AM <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
Re: [PATCH net-next] net: dsa: motorcomm: Unregister the MDIO buses on teardown
Author: Andrew Lunn
Date: Thu, 26 Nov 2026 13:53
Date: Thu, 26 Nov 2026 13:53
12 lines
8454 bytes
8454 bytes
> +void yt921x_mbus_int_remove(struct yt921x_priv *priv)
> +{
> + struct mii_bus *mbus = priv->mbus_int;
> +
> + if (!mbus)
> + return;
Can mbus be NULL when this function is called? Either setup was
successful and it exists, or setup failed and it does not.
Andrew
Re: [PATCH net-next] net: dsa: motorcomm: Unregister the MDIO buses on teardown
Author: netdev-bot+sashiko
Date: Fri, 27 Nov 2026 04:14
Date: Fri, 27 Nov 2026 04:14
94 lines
10920 bytes
10920 bytes
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 0 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] The patch switches the yt921x internal and external MDIO buses from devm-managed allocation and registration to manual… -- net: dsa: motorcomm: Unregister the MDIO buses on teardown The yt921x internal and external MDIO buses used devm-managed allocation and registration. This patch replaces that with mdiobus_alloc() plus of_mdiobus_register(), and frees the buses in .teardown() and on the yt921x_dsa_setup() error paths. A second .setup() within one registration should then no longer collide with a bus that is still registered. > diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c > index a21d4bb5e1412..789a08dbe3b93 100644 > --- a/drivers/net/dsa/motorcomm/chip.c > +++ b/drivers/net/dsa/motorcomm/chip.c [ ... ] > @@ -2586,7 +2590,7 @@ 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) [Severity: High] Should the yt921x_devlink_setup() failure also go to err? After this patch it still reads: res = yt921x_devlink_setup(priv); if (res) return res; If that fails, priv->mbus_int and priv->mbus_ext stay registered and allocated. The DSA core does not call ops->teardown() when ops->setup() fails. dsa_switch_setup() in net/dsa/dsa.c does: err = ds->ops->setup(ds); if (err < 0) goto unregister_notifier; That jump skips the teardown label. ds->setup also stays false, so dsa_switch_teardown() returns early. On this path yt921x_dsa_teardown() never runs. Before this patch, devm_of_mdiobus_register() cleaned up in this case. Now nothing unregisters or frees the buses, and mbus->priv still points at the devm-allocated priv from yt921x_mdio_probe(). priv is freed when the probe fails, or in a multi-chip tree when the switch is later unbound. After that, any access through the leaked bus reaches yt921x_mbus_int_read() or yt921x_mbus_int_write(), which call mutex_lock(&priv->reg_lock) on freed memory. If the module has been unloaded, the callbacks point into freed module text instead. The leaked bus also keeps its id (dev_name(dev)) under the same parent. Could a later setup or re-probe then hit the same __mdiobus_register() collision that this patch is meant to fix? Replacing the return res above with goto err would close this path. > @@ -2599,6 +2603,12 @@ static int yt921x_dsa_setup(struct dsa_switch *ds) > #endif > > return 0; > + > +err: > + yt921x_mbus_ext_remove(priv); > +err_mbus_int: > + yt921x_mbus_int_remove(priv); > + return res; > } -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126034725.64709-1-mmyangfl%40gmail.com
Re: [PATCH net-next] net: dsa: motorcomm: Unregister the MDIO buses on teardown
Author: David Yang
Date: Fri, 27 Nov 2026 04:34
Date: Fri, 27 Nov 2026 04:34
16 lines
12322 bytes
12322 bytes
On Thu, Nov 26, 2026 at 9:53 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> > +void yt921x_mbus_int_remove(struct yt921x_priv *priv)
> > +{
> > + struct mii_bus *mbus = priv->mbus_int;
> > +
> > + if (!mbus)
> > + return;
>
> Can mbus be NULL when this function is called? Either setup was
> successful and it exists, or setup failed and it does not.
>
> Andrew
Yes, mdio and mdio-external are optional.
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