From: netdev-bot+sashiko@kernel.org
To: mmyangfl@gmail.com
Cc: netdev@vger.kernel.org, andrew@lunn.ch, olteanv@gmail.com,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, linux@armlinux.org.uk
Subject: Re: [PATCH net-next] net: dsa: motorcomm: Unregister the MDIO buses on teardown
Date: Fri, 27 Nov 2026 04:14:33 +0000 [thread overview]
Message-ID: <179575287341.3135.2545531095986940323@kernel.org> (raw)
In-Reply-To: <20261126034725.64709-1-mmyangfl@gmail.com>
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
prev parent reply other threads:[~2026-11-27 4:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 3:47 [PATCH net-next] net: dsa: motorcomm: Unregister the MDIO buses on teardown David Yang
2026-11-26 3:52 ` netdev-bot+sinfo
2026-11-26 4:00 ` David Yang
2026-11-26 13:53 ` Andrew Lunn
2026-11-27 4:34 ` David Yang
2026-11-27 4:14 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179575287341.3135.2545531095986940323@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mmyangfl@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox