* [PATCH] net: bgmac: fix refcount leak in bgmac_phy_connect_direct()
@ 2026-06-09 7:44 Wentao Liang
2026-06-11 14:42 ` Simon Horman
0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-06-09 7:44 UTC (permalink / raw)
To: rafal, bcm-kernel-feedback-list, andrew+netdev, davem, edumazet,
kuba, pabeni
Cc: netdev, linux-kernel, Wentao Liang, stable
In bgmac_phy_connect_direct(), fixed_phy_register() returns a
phy_device with an incremented refcount. If the subsequent
phy_connect_direct() call fails, the function returns the error
without releasing the phy_device reference. Add the missing
fixed_phy_unregister() in the error path to prevent the leak.
Cc: stable@vger.kernel.org
Fixes: c25b23b8a387 ("bgmac: register fixed PHY for ARM BCM470X / BCM5301X chipsets")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/net/ethernet/broadcom/bgmac.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
index 3e9c57196a39..c97cf7ebad7f 100644
--- a/drivers/net/ethernet/broadcom/bgmac.c
+++ b/drivers/net/ethernet/broadcom/bgmac.c
@@ -1456,6 +1456,7 @@ int bgmac_phy_connect_direct(struct bgmac *bgmac)
PHY_INTERFACE_MODE_MII);
if (err) {
dev_err(bgmac->dev, "Connecting PHY failed\n");
+ fixed_phy_unregister(phy_dev);
return err;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: bgmac: fix refcount leak in bgmac_phy_connect_direct()
2026-06-09 7:44 [PATCH] net: bgmac: fix refcount leak in bgmac_phy_connect_direct() Wentao Liang
@ 2026-06-11 14:42 ` Simon Horman
0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2026-06-11 14:42 UTC (permalink / raw)
To: vulab
Cc: Simon Horman, rafal, bcm-kernel-feedback-list, andrew+netdev,
davem, edumazet, kuba, pabeni, netdev, linux-kernel, stable
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev
Simon says:
Although the issues reported below are flagged as pre-existing
I wonder if they should be considered in the scope of this patch (set)
as they appear to be similar issues to the one this patch addresses.
---
net: bgmac: fix refcount leak in bgmac_phy_connect_direct()
In bgmac_phy_connect_direct(), fixed_phy_register() returns a
phy_device with an incremented refcount. If the subsequent
phy_connect_direct() call fails, the function returns the error
without releasing the phy_device reference. Add the missing
fixed_phy_unregister() in the error path to prevent the leak.
> diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
> index 3e9c57196a397..c97cf7ebad7f1 100644
> --- a/drivers/net/ethernet/broadcom/bgmac.c
> +++ b/drivers/net/ethernet/broadcom/bgmac.c
> @@ -1456,6 +1456,7 @@ int bgmac_phy_connect_direct(struct bgmac *bgmac)
> PHY_INTERFACE_MODE_MII);
> if (err) {
> dev_err(bgmac->dev, "Connecting PHY failed\n");
> + fixed_phy_unregister(phy_dev);
[Severity: High]
This isn't a bug introduced by this patch, but does this driver still leak
the fixed phy identifier during driver teardown and in other error paths?
In bgmac_enet_remove(), the driver calls phy_disconnect() but does not
appear to unregister the fixed phy:
drivers/net/ethernet/broadcom/bgmac.c:bgmac_enet_remove() {
unregister_netdev(bgmac->net_dev);
phy_disconnect(bgmac->net_dev->phydev);
netif_napi_del(&bgmac->napi);
bgmac_dma_free(bgmac);
}
Similarly, in the error path of bgmac_enet_probe():
drivers/net/ethernet/broadcom/bgmac.c:bgmac_enet_probe() {
...
err_phy_disconnect:
phy_disconnect(net_dev->phydev);
...
}
Since fixed_phy_register() allocates an identifier from fixed_phy_ids (which
has a hard limit of 8 slots), failing to unregister it means the identifier
is never released. After 8 unbind or bind cycles or probe failures, the
fixed_phy_ids bitmap will be exhausted, permanently failing subsequent probes.
Should fixed_phy_unregister() also be called in these paths to prevent
exhausting the fixed phy identifiers?
> return err;
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-11 14:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-09 7:44 [PATCH] net: bgmac: fix refcount leak in bgmac_phy_connect_direct() Wentao Liang
2026-06-11 14:42 ` Simon Horman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.