* Re: [PATCH net] net: bgmac: unregister the fixed PHY on probe failure and removal
2026-11-20 0:30 [PATCH net] net: bgmac: unregister the fixed PHY on probe failure and removal Florian Fainelli
@ 2026-11-20 0:32 ` netdev-bot+sinfo
2026-11-20 0:34 ` Florian Fainelli
2026-11-24 0:40 ` netdev-bot+sashiko
1 sibling, 1 reply; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-20 0:32 UTC (permalink / raw)
To: Florian Fainelli
Cc: netdev, rosenp, Rafał Miłecki,
Broadcom internal kernel review list, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel
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.
- What hardware the change was tested on. For driver fixes please
mention the device (and if relevant firmware version) used for
testing, or say that the change was not tested on real hardware.
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: bgmac: unregister the fixed PHY on probe failure and removal
2026-11-20 0:30 [PATCH net] net: bgmac: unregister the fixed PHY on probe failure and removal Florian Fainelli
2026-11-20 0:32 ` netdev-bot+sinfo
@ 2026-11-24 0:40 ` netdev-bot+sashiko
1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 0:40 UTC (permalink / raw)
To: florian.fainelli
Cc: netdev, rosenp, rafal, bcm-kernel-feedback-list, andrew+netdev,
davem, edumazet, kuba, pabeni, linux-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 (1) · 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 new bgmac_phy_disconnect() reads phydev after
phy_disconnect() may have freed it, which is a use-after-free on the…
- [Medium] bgmac_phy_disconnect() picks the release method from the
device tree, not from how the connected PHY was registered.
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but
of_phy_get_and_connect() in drivers/net/mdio/of_mdio.c can leak a…
--
net: bgmac: unregister the fixed PHY on probe failure and removal
This patch adds bgmac_phy_disconnect(). It disconnects the PHY and then
releases any fixed PHY, using of_phy_deregister_fixed_link() for DT
fixed-link nodes and fixed_phy_unregister() otherwise. The helper is used
on the bgmac_enet_probe() error path and in bgmac_enet_remove(). Also,
bgmac_phy_connect_direct() now unregisters its fixed PHY when
phy_connect_direct() fails.
> diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
> index 9ef7307edd41e..54092bfacd189 100644
> --- a/drivers/net/ethernet/broadcom/bgmac.c
> +++ b/drivers/net/ethernet/broadcom/bgmac.c
[ ... ]
> @@ -1482,6 +1484,22 @@ int bgmac_phy_connect_direct(struct bgmac *bgmac)
> }
> EXPORT_SYMBOL_GPL(bgmac_phy_connect_direct);
>
> +/* Disconnect the PHY and release a fixed PHY registered for the connection. */
> +static void bgmac_phy_disconnect(struct bgmac *bgmac)
> +{
> + struct device_node *np = bgmac->dev->of_node;
> + struct phy_device *phydev = bgmac->net_dev->phydev;
> +
> + if (!phydev)
> + return;
> +
> + phy_disconnect(phydev);
> + if (np && of_phy_is_fixed_link(np))
> + of_phy_deregister_fixed_link(np);
[Severity: Medium]
Does this leak the fixed PHY created by bgmac_phy_connect_direct() when
the DT node also satisfies of_phy_is_fixed_link()?
The branch is picked from the DT node, not from how the connected PHY was
registered. bgmac_phy_connect_direct() registers its PHY with no of_node:
phy_dev = fixed_phy_register(&fphy_status, NULL);
So of_phy_deregister_fixed_link(np) can't find it through
of_phy_find_device(np) and returns without a warning. Because the fallback
is an else-if, fixed_phy_unregister() never runs.
There seem to be two ways to end up here. In bgmac-platform.c,
bgmac_probe() picks bgmac_phy_connect_direct() whenever phy-handle is
missing:
phy_node = of_parse_phandle(np, "phy-handle", 0);
if (phy_node) {
of_node_put(phy_node);
bgmac->phy_connect = platform_phy_connect;
} else {
bgmac->phy_connect = bgmac_phy_connect_direct;
brcm,amac.yaml references ethernet-controller.yaml, so a node with a
fixed-link child or a managed property and no phy-handle passes the
schema.
In bgmac-bcma.c, bcma_phy_connect() falls back to
bgmac_phy_connect_direct() when of_phy_get_and_connect() returns NULL. One
case is a fixed-link node without phy-mode. Another is of_phy_connect()
failing after of_phy_register_fixed_link() has already succeeded. In that
second case, teardown would remove the stale, unconnected DT fixed PHY and
leak the connected direct one.
None of the in-tree DTs seem to hit this today. The gmac nodes in
bcm-ns.dtsi and bcm53573.dtsi have both phy-mode and fixed-link. Still,
this is the same leak the commit message describes.
Could the release method be based on the phydev itself? For example,
call of_phy_deregister_fixed_link() only when the phydev's fwnode matches
np, and otherwise call fixed_phy_unregister() for any pseudo fixed link.
> + else if (phy_is_pseudo_fixed_link(phydev))
> + fixed_phy_unregister(phydev);
[Severity: High]
Can phy_is_pseudo_fixed_link(phydev) read freed memory here?
On the bcma remove path, bgmac_remove() unregisters the MDIO bus before
it calls bgmac_enet_remove():
drivers/net/ethernet/broadcom/bgmac-bcma.c:bgmac_remove() {
...
bcma_mdio_mii_unregister(bgmac->mii_bus);
bgmac_enet_remove(bgmac);
...
}
mdiobus_unregister() calls device_remove() and then device_free() on the
PHY at bgmac->phyaddr, which drops the registration reference. After that,
the only reference left is the get_device() taken in phy_attach_direct().
The call chain is then:
bgmac_enet_remove()
bgmac_phy_disconnect()
phy_disconnect()
phy_detach()
phy_detach_internal()
put_device(&phydev->mdio.dev) <- can free phydev
phy_detach_internal() itself has a comment warning that "The phydev might
go away on the put_device() below".
The first condition is false when np is NULL (BCM47xx without DT). It is
also false on DT boards whose gmac uses phy-handle and has no fixed-link.
In both cases the else-if reads phydev->is_pseudo_fixed_link from the
freed object. If that stale bit reads as set, fixed_phy_unregister() runs
on freed memory.
Before this patch, bgmac_enet_remove() did not touch phydev after
phy_disconnect().
Would it work to evaluate phy_is_pseudo_fixed_link(phydev) and the DT
check before calling phy_disconnect()? Separately, could bgmac_remove() be
reordered so that bgmac_enet_remove() runs before
bcma_mdio_mii_unregister()?
> +}
> +
> struct bgmac *bgmac_alloc(struct device *dev)
> {
> struct net_device *net_dev;
> @@ -1575,7 +1593,7 @@ int bgmac_enet_probe(struct bgmac *bgmac)
> return 0;
>
> err_phy_disconnect:
> - phy_disconnect(net_dev->phydev);
> + bgmac_phy_disconnect(bgmac);
> err_dma_free:
> bgmac_dma_free(bgmac);
[Severity: Medium]
This is a pre-existing issue, not one introduced by this patch. Is the DT
fixed PHY leaked when bgmac_phy_connect() fails and probe jumps to
err_dma_free?
If of_phy_connect() fails, of_phy_get_and_connect() returns NULL without
deregistering the fixed link it just registered:
drivers/net/mdio/of_mdio.c:of_phy_get_and_connect() {
...
if (of_phy_is_fixed_link(np)) {
ret = of_phy_register_fixed_link(np);
...
phy = of_phy_connect(dev, phy_np, hndlr, 0, iface);
of_node_put(phy_np);
return phy;
}
In bgmac-platform.c, platform_phy_connect() turns that into -ENODEV.
bgmac_enet_probe() then takes the err_dma_free path and skips
bgmac_phy_disconnect(). Calling it wouldn't help anyway, because
net_dev->phydev is NULL at that point.
In bgmac-bcma.c, bcma_phy_connect() then falls back to phy_connect() or
bgmac_phy_connect_direct(). That can leave two fixed PHYs registered.
This should be rare: of_phy_connect() on a freshly registered fixed PHY
mostly fails only on allocation errors. Other users of this helper, such
as ftgmac100 and gemini, don't clean up on this failure either.
> err_out:
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120003044.2366432-1-florian.fainelli%40broadcom.com
^ permalink raw reply [flat|nested] 4+ messages in thread