From: sashiko-bot@kernel.org
To: "Caleb James DeLisle" <cjd@cjdns.fr>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [net-next v5 5/7] net: dsa: mediatek: support MDIO switch downstream of MMIO switch
Date: Tue, 17 Nov 2026 18:35:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-219354@kernel.org> (raw)
In-Reply-To: <20261116183332.168858-6-cjd@cjdns.fr>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] net: dsa: mt7530: missing dsa_unregister_switch() on probe MDIO
setup error
- [High] net: dsa: mt7530: duplicate mt7530_setup_irq() call in
mt7530_setup_mdio()
- [High] net: dsa: mt7530: premature and re-entrant mt7530_setup_mdio()
in mt7988_probe()
--
commit ef65040817a2e220996466f22eb74590c98e4476
Author: Caleb James DeLisle <cjd@cjdns.fr>
net: dsa: mediatek: support MDIO switch downstream of MMIO switch
This commit enables probing an MDIO switch connected to the MDIO bus of
an upstream MMIO switch by calling mt7530_setup_mdio() from
mt7988_probe() and assigning separate lockdep classes to MMIO and MDIO
reg_mutex instances.
> diff --git a/drivers/net/dsa/mt7530-mmio.c b/drivers/net/dsa/mt7530-mmio.c
> index 5d467be2a32c8..ab6d92ab3ec0b 100644
> --- a/drivers/net/dsa/mt7530-mmio.c
> +++ b/drivers/net/dsa/mt7530-mmio.c
> @@ -61,7 +62,27 @@ mt7988_probe(struct platform_device *pdev)
> if (IS_ERR(priv->regmap))
> return PTR_ERR(priv->regmap);
>
> - return dsa_register_switch(priv->ds);
> + ret = dsa_register_switch(priv->ds);
> +
> + if (ret)
> + return ret;
> +
> + /*
> + * If not all switches in the hierarchy have been probed,
> + * dsa_register_switch() returns 0 without calling mt753x_setup().
> + * Call mt7530_setup_mdio() because there's a chance that the missing
> + * switch is on the MDIO bus. If "mdio" node is not present then there
> + * is definitely no MDIO switch in the DT, and also if "mdio" is not
> + * present then phys_mii_mask is relevant and that is not set until
> + * dsa_switch_setup.
> + */
> + mnp = of_get_child_by_name(pdev->dev.of_node, "mdio");
> + if (mnp) {
> + of_node_put(mnp);
> + ret = mt7530_setup_mdio(priv);
> + }
[Severity: High]
Does calling mt7530_setup_mdio() here before mt7988_setup() has run cause
the later switch setup to wipe out the IRQ and PHY state, and break PHY
attachment for ports listed after the downstream switch in DT?
When the DSA tree is incomplete, dsa_register_switch() returns 0 without
running mt753x_setup() -> mt7988_setup(). Calling mt7530_setup_mdio() at
that point registers the IRQ chip (programming MT7530_SYS_INT_EN) and the
MDIO bus before mt7988_setup() has deasserted priv->rstc or configured
PHY clocks. When the downstream switch probes on that MDIO bus and
completes the tree, dsa_tree_setup() runs mt7988_setup() on the upstream
switch:
drivers/net/dsa/mt7530.c:mt7988_setup() {
/* Reset the switch */
reset_control_assert(priv->rstc);
usleep_range(20, 50);
reset_control_deassert(priv->rstc);
...
/* Reset the switch PHYs */
regmap_write(priv->regmap, MT7530_SYS_CTRL, SYS_CTRL_PHY_RST);
}
Asserting priv->rstc and SYS_CTRL_PHY_RST resets the upstream switch and
its PHYs after the IRQ controller and MDIO devices have already been
configured, and the subsequent mt7530_setup_mdio() call in mt753x_setup()
is a no-op because priv->child_bus is already set.
In addition, devm_of_mdiobus_register() probes the downstream switch
synchronously while __of_mdiobus_parse_phys() is still iterating over the
children of the "mdio" node:
mt7988_probe()
mt7530_setup_mdio()
priv->child_bus = bus;
devm_of_mdiobus_register()
__of_mdiobus_parse_phys()
of_mdiobus_register_device() [downstream switch]
...
dsa_register_switch()
dsa_tree_setup()
dsa_tree_setup_switches()
mt753x_setup()
mt7530_setup_mdio() <-- returns 0 (priv->child_bus set)
dsa_tree_setup_ports()
phylink_of_phy_connect() <-- -ENODEV for later PHY nodes
Any PHY child nodes appearing after the downstream switch node in the
"mdio" DT node have not been registered yet when dsa_tree_setup_ports()
runs, so phylink_of_phy_connect() fails with -ENODEV and DSA disables
those ports via dsa_port_setup_as_unused().
> +
> + return ret;
> }
[Severity: High]
If mt7530_setup_mdio() fails here (for instance with -EPROBE_DEFER from
of_irq_get()), does returning ret without calling dsa_unregister_switch()
leave dangling pointers to priv->ds in dst->ports?
priv->ds is allocated with devm_kzalloc_obj() on &pdev->dev, whereas
dsa_register_switch() allocates non-devm dsa_port structures linked into
dst->ports with dp->ds pointing to priv->ds. When probe fails, devres
frees priv->ds without running mt7988_remove(), leaking the dsa_port
allocations and conduit reference and causing a use-after-free when a
subsequent probe or peer switch registration walks dst->ports in
dsa_switch_find() and dereferences dp->ds->index.
> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index 53ac692d5ba93..4390982a5e225 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
[ ... ]
> @@ -2530,7 +2525,7 @@ mt7530_free_mdio_irq(struct mt7530_priv *priv)
> }
> }
>
> -static int
> +int
> mt7530_setup_mdio(struct mt7530_priv *priv)
> {
> struct device_node *mnp, *np = priv->dev->of_node;
> @@ -2540,6 +2535,14 @@ mt7530_setup_mdio(struct mt7530_priv *priv)
> static int idx;
> int ret = 0;
>
> + /* Already done */
> + if (priv->child_bus)
> + return 0;
> +
> + ret = mt7530_setup_irq(priv);
> + if (ret)
> + return ret;
> +
> mnp = of_get_child_by_name(np, "mdio");
>
> if (mnp && !of_device_is_available(mnp))
[Severity: High]
Can mt7530_setup_irq() be called twice if the "mdio" child node is
disabled in DT?
When the "mdio" node has status = "disabled", the first call to
mt7530_setup_mdio() from mt753x_setup() runs mt7530_setup_irq() and then
jumps to out before setting priv->child_bus. In mt7988_probe(),
of_get_child_by_name() still returns the disabled "mdio" node and calls
mt7530_setup_mdio() a second time. Because priv->child_bus is still NULL,
mt7530_setup_irq() runs again and devm_regmap_add_irq_chip_fwnode() fails
with -EBUSY when requesting the non-shared IRQF_ONESHOT interrupt a
second time.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116183332.168858-1-cjd@cjdns.fr?part=5
next prev parent reply other threads:[~2026-11-17 18:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 18:33 [net-next v5 0/7] net: dsa: mt7530: support EcoNet EN751221 Caleb James DeLisle
2026-11-16 18:33 ` [net-next v5 1/7] net: dsa: mt7530: get ctrl phy addr using a function Caleb James DeLisle
2026-11-16 18:33 ` [net-next v5 2/7] dt-bindings: net: dsa: mediatek,mt7530: describe 'passthrough' hierarchy Caleb James DeLisle
2026-11-16 18:33 ` [net-next v5 3/7] net: dsa: mediatek: add support for passthrough mode Caleb James DeLisle
2026-11-17 0:30 ` kernel test robot
2026-11-17 18:35 ` sashiko-bot
2026-11-16 18:33 ` [net-next v5 4/7] net: dsa: mediatek: support PLL setup on MMIO MT7530 Caleb James DeLisle
2026-11-17 18:35 ` sashiko-bot
2026-11-16 18:33 ` [net-next v5 5/7] net: dsa: mediatek: support MDIO switch downstream of MMIO switch Caleb James DeLisle
2026-11-17 18:35 ` sashiko-bot [this message]
2026-11-16 18:33 ` [net-next v5 6/7] dt-bindings: net: dsa: mediatek,mt7530: add EcoNet EN751221 switches Caleb James DeLisle
2026-11-17 18:35 ` sashiko-bot
2026-11-16 18:33 ` [net-next v5 7/7] net: dsa: mediatek: support EN751221 switch Caleb James DeLisle
2026-11-17 18:35 ` sashiko-bot
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=sashiko-outbox-219354@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=cjd@cjdns.fr \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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