mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net: thunderx: fix fwnode_handle leak in bgx_init_of_phy()
@ 2026-10-25 20:31 Selby Mashiki
  2026-10-25 20:35 ` netdev-bot+sinfo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Selby Mashiki @ 2026-10-25 20:31 UTC (permalink / raw)
  To: Sunil Goutham, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-arm-kernel, netdev, linux-kernel, Selby Mashiki

In bgx_init_of_phy(), device_for_each_child_node(&bgx->pdev->dev, fwn)
breaks out of the loop without calling fwnode_handle_put(fwn) if
to_of_node(fwn) returns NULL.

Switch the loop to device_for_each_child_node_scoped() and remove the
manual of_node_put(node) calls so the child fwnode_handle reference is
automatically released on all loop exit paths.

Fixes: 9d28f9491258 ("net: thunder_bgx: add a missing of_node_put")
Signed-off-by: Selby Mashiki <mashikiselby@gmail.com>
---
 drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index b63039999..3fe3f80db 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -1467,11 +1467,10 @@ static int bgx_init_acpi_phy(struct bgx *bgx)
 
 static int bgx_init_of_phy(struct bgx *bgx)
 {
-	struct fwnode_handle *fwn;
 	struct device_node *node = NULL;
 	u8 lmac = 0;
 
-	device_for_each_child_node(&bgx->pdev->dev, fwn) {
+	device_for_each_child_node_scoped(&bgx->pdev->dev, fwn) {
 		struct phy_device *pd;
 		struct device_node *phy_np;
 
@@ -1506,10 +1505,8 @@ static int bgx_init_of_phy(struct bgx *bgx)
 		}
 
 		lmac++;
-		if (lmac == bgx->max_lmac) {
-			of_node_put(node);
+		if (lmac == bgx->max_lmac)
 			break;
-		}
 	}
 	return 0;
 
@@ -1524,7 +1521,6 @@ static int bgx_init_of_phy(struct bgx *bgx)
 			bgx->lmac[lmac].phydev = NULL;
 		}
 	}
-	of_node_put(node);
 	return -EPROBE_DEFER;
 }
 
-- 
2.56.0

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

* Re: [PATCH] net: thunderx: fix fwnode_handle leak in bgx_init_of_phy()
  2026-10-25 20:31 [PATCH] net: thunderx: fix fwnode_handle leak in bgx_init_of_phy() Selby Mashiki
@ 2026-10-25 20:35 ` netdev-bot+sinfo
  2026-10-25 20:37 ` Selby Mashiki
  2026-10-26  2:02 ` Andrew Lunn
  2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-10-25 20:35 UTC (permalink / raw)
  To: Selby Mashiki
  Cc: Sunil Goutham, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-arm-kernel, netdev,
	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 code inspection). If it was triggered please include
   the symptoms, like the stack trace or error 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. If the series needs another revision for
other reasons, please include the information in the commit messages
then.

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: thunderx: fix fwnode_handle leak in bgx_init_of_phy()
  2026-10-25 20:31 [PATCH] net: thunderx: fix fwnode_handle leak in bgx_init_of_phy() Selby Mashiki
  2026-10-25 20:35 ` netdev-bot+sinfo
@ 2026-10-25 20:37 ` Selby Mashiki
  2026-10-26  2:02 ` Andrew Lunn
  2 siblings, 0 replies; 4+ messages in thread
From: Selby Mashiki @ 2026-10-25 20:37 UTC (permalink / raw)
  To: Sunil Goutham, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-arm-kernel, netdev, linux-kernel, Selby Mashiki

Hi,

Here is the additional information requested by the bot:

- Discovery: Found via a static analysis script scanning for
  device_for_each_child_node() / fwnode_for_each_child_node() loops that
  exit early without releasing the child fwnode_handle reference,
  followed by manual code inspection.
- Triggered vs. theoretical: Theoretical (found by static analysis and
  code inspection, not triggered at runtime).
- Hardware testing: Compile-tested only (-Werror); not tested on real
  Cavium ThunderX hardware as I do not have access to the device.

Best regards,
Selby Mashiki

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

* Re: [PATCH] net: thunderx: fix fwnode_handle leak in bgx_init_of_phy()
  2026-10-25 20:31 [PATCH] net: thunderx: fix fwnode_handle leak in bgx_init_of_phy() Selby Mashiki
  2026-10-25 20:35 ` netdev-bot+sinfo
  2026-10-25 20:37 ` Selby Mashiki
@ 2026-10-26  2:02 ` Andrew Lunn
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2026-10-26  2:02 UTC (permalink / raw)
  To: Selby Mashiki
  Cc: Sunil Goutham, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-arm-kernel, netdev,
	linux-kernel

On Sun, Oct 25, 2026 at 10:31:59PM +0200, Selby Mashiki wrote:
> In bgx_init_of_phy(), device_for_each_child_node(&bgx->pdev->dev, fwn)
> breaks out of the loop without calling fwnode_handle_put(fwn) if
> to_of_node(fwn) returns NULL.
> 
> Switch the loop to device_for_each_child_node_scoped() and remove the
> manual of_node_put(node) calls so the child fwnode_handle reference is
> automatically released on all loop exit paths.
> 
> Fixes: 9d28f9491258 ("net: thunder_bgx: add a missing of_node_put")
> Signed-off-by: Selby Mashiki <mashikiselby@gmail.com>

Does a leaked OF node bother anybody? I would say no, so please post
this to net-next.

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

	Andrew

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

end of thread, other threads:[~2026-10-26  2:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-25 20:31 [PATCH] net: thunderx: fix fwnode_handle leak in bgx_init_of_phy() Selby Mashiki
2026-10-25 20:35 ` netdev-bot+sinfo
2026-10-25 20:37 ` Selby Mashiki
2026-10-26  2:02 ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®