Netdev List
 help / color / mirror / Atom feed
* [PATCH] net: mvmdio: fix clk reference leak in orion_mdio_probe()
@ 2026-10-08 16:53 Haotian Zhang
  2026-10-08 16:59 ` netdev-bot+sinfo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Haotian Zhang @ 2026-10-08 16:53 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Josua Mayer
  Cc: netdev, linux-kernel

orion_mdio_probe() calls of_clk_get() with index ARRAY_SIZE(dev->clk)
purely to test whether the device tree declares more clocks than the
driver supports.  of_clk_get() takes a reference on the returned clk,
but the return value is only checked with IS_ERR() and never released,
so both the clk reference and the clk allocated by alloc_clk() are leaked
whenever the DT node has more than four clocks.

Store the returned clk in a local variable and release it with clk_put()
after emitting the warning.

Fixes: ea664b1bdc19 ("net: mvmdio: print warning when orion-mdio has too many clocks")
Assisted-by: DeepSeek-V4.1-Flash
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 drivers/net/ethernet/marvell/mvmdio.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c
index 2ccb8c8f5feb..17537142be6d 100644
--- a/drivers/net/ethernet/marvell/mvmdio.c
+++ b/drivers/net/ethernet/marvell/mvmdio.c
@@ -286,6 +286,7 @@ static int orion_mdio_probe(struct platform_device *pdev)
 	struct resource *r;
 	struct mii_bus *bus;
 	struct orion_mdio_dev *dev;
+	struct clk *clk;
 	int i, ret;
 
 	type = (uintptr_t)device_get_match_data(&pdev->dev);
@@ -338,11 +339,13 @@ static int orion_mdio_probe(struct platform_device *pdev)
 			clk_prepare_enable(dev->clk[i]);
 		}
 
-		if (!IS_ERR(of_clk_get(pdev->dev.of_node,
-				       ARRAY_SIZE(dev->clk))))
+		clk = of_clk_get(pdev->dev.of_node, ARRAY_SIZE(dev->clk));
+		if (!IS_ERR(clk)) {
 			dev_warn(&pdev->dev,
 				 "unsupported number of clocks, limiting to the first "
 				 __stringify(ARRAY_SIZE(dev->clk)) "\n");
+			clk_put(clk);
+		}
 
 		if (type == BUS_TYPE_XSMI)
 			orion_mdio_xsmi_set_mdc_freq(bus);
-- 
2.25.1


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

end of thread, other threads:[~2026-10-09  6:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-08 16:53 [PATCH] net: mvmdio: fix clk reference leak in orion_mdio_probe() Haotian Zhang
2026-10-08 16:59 ` netdev-bot+sinfo
2026-10-08 19:20 ` Andrew Lunn
2026-10-09  6:10 ` Krzysztof Kozlowski

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