From: Simon Horman <horms@kernel.org>
To: vulab@iscas.ac.cn
Cc: Simon Horman <horms@kernel.org>,
rafal@milecki.pl, bcm-kernel-feedback-list@broadcom.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] net: bgmac: fix refcount leak in bgmac_phy_connect_direct()
Date: Thu, 11 Jun 2026 15:42:02 +0100 [thread overview]
Message-ID: <20260611144200.600147-3-horms@kernel.org> (raw)
In-Reply-To: <20260609074411.205176-1-vulab@iscas.ac.cn>
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;
> }
>
prev parent reply other threads:[~2026-06-11 14:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 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=20260611144200.600147-3-horms@kernel.org \
--to=horms@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rafal@milecki.pl \
--cc=stable@vger.kernel.org \
--cc=vulab@iscas.ac.cn \
/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