netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net: ethernet: bgmac-platform: fix an OF node reference leak
@ 2024-12-14  1:49 Joe Hattori
  2024-12-16 14:56 ` Simon Horman
  2024-12-17 12:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Joe Hattori @ 2024-12-14  1:49 UTC (permalink / raw)
  To: rafal, bcm-kernel-feedback-list, andrew+netdev, davem, edumazet,
	kuba, pabeni
  Cc: netdev, Joe Hattori

The OF node obtained by of_parse_phandle() is not freed. Call
of_node_put() to balance the refcount.

This bug was found by an experimental static analysis tool that I am
developing.

Fixes: 1676aba5ef7e ("net: ethernet: bgmac: device tree phy enablement")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
Changes in V2:
- Avoid using the __free() construct.
---
 drivers/net/ethernet/broadcom/bgmac-platform.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/broadcom/bgmac-platform.c b/drivers/net/ethernet/broadcom/bgmac-platform.c
index ecce23cecbea..4e266ce41180 100644
--- a/drivers/net/ethernet/broadcom/bgmac-platform.c
+++ b/drivers/net/ethernet/broadcom/bgmac-platform.c
@@ -171,6 +171,7 @@ static int platform_phy_connect(struct bgmac *bgmac)
 static int bgmac_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
+	struct device_node *phy_node;
 	struct bgmac *bgmac;
 	struct resource *regs;
 	int ret;
@@ -236,7 +237,9 @@ static int bgmac_probe(struct platform_device *pdev)
 	bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset;
 	bgmac->get_bus_clock = platform_bgmac_get_bus_clock;
 	bgmac->cmn_maskset32 = platform_bgmac_cmn_maskset32;
-	if (of_parse_phandle(np, "phy-handle", 0)) {
+	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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] net: ethernet: bgmac-platform: fix an OF node reference leak
  2024-12-14  1:49 [PATCH v2] net: ethernet: bgmac-platform: fix an OF node reference leak Joe Hattori
@ 2024-12-16 14:56 ` Simon Horman
  2024-12-17 12:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2024-12-16 14:56 UTC (permalink / raw)
  To: Joe Hattori
  Cc: rafal, bcm-kernel-feedback-list, andrew+netdev, davem, edumazet,
	kuba, pabeni, netdev

On Sat, Dec 14, 2024 at 10:49:12AM +0900, Joe Hattori wrote:
> The OF node obtained by of_parse_phandle() is not freed. Call
> of_node_put() to balance the refcount.
> 
> This bug was found by an experimental static analysis tool that I am
> developing.
> 
> Fixes: 1676aba5ef7e ("net: ethernet: bgmac: device tree phy enablement")
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
> ---
> Changes in V2:
> - Avoid using the __free() construct.

Thanks for the update.

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] net: ethernet: bgmac-platform: fix an OF node reference leak
  2024-12-14  1:49 [PATCH v2] net: ethernet: bgmac-platform: fix an OF node reference leak Joe Hattori
  2024-12-16 14:56 ` Simon Horman
@ 2024-12-17 12:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-12-17 12:30 UTC (permalink / raw)
  To: Joe Hattori
  Cc: rafal, bcm-kernel-feedback-list, andrew+netdev, davem, edumazet,
	kuba, pabeni, netdev

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Sat, 14 Dec 2024 10:49:12 +0900 you wrote:
> The OF node obtained by of_parse_phandle() is not freed. Call
> of_node_put() to balance the refcount.
> 
> This bug was found by an experimental static analysis tool that I am
> developing.
> 
> Fixes: 1676aba5ef7e ("net: ethernet: bgmac: device tree phy enablement")
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
> 
> [...]

Here is the summary with links:
  - [v2] net: ethernet: bgmac-platform: fix an OF node reference leak
    https://git.kernel.org/netdev/net/c/0cb2c504d79e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-12-17 12:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-14  1:49 [PATCH v2] net: ethernet: bgmac-platform: fix an OF node reference leak Joe Hattori
2024-12-16 14:56 ` Simon Horman
2024-12-17 12:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).