Thread (2 messages) 2 messages, 1 author, 15d ago
COLD15d

[PATCH] fix: net: marvell: orion_mdio_probe: fix clock reference leak on extra clock detection

From: WenTao Liang <hidden>
Date: 2026-06-26 15:19:35
Also in: lkml, stable
Subsystem: networking drivers, the rest · Maintainers: Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

The code calls of_clk_get(pdev->dev.of_node, ARRAY_SIZE(dev->clk)) to
  detect unsupported extra clocks. If an extra clock exists, the function
  prints a warning but discards the returned clk pointer without calling
  clk_put, leaking a clock reference on every probe.

Store the returned clock and call clk_put after the warning to properly
  release the acquired reference.

Cc: stable@vger.kernel.org
Fixes: ea664b1bdc19 ("net: mvmdio: print warning when orion-mdio has too many clocks")
Signed-off-by: WenTao Liang <redacted>
---
 drivers/net/ethernet/marvell/mvmdio.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c
index 3f4447e68888..4e5b5c5f7301 100644
--- a/drivers/net/ethernet/marvell/mvmdio.c
+++ b/drivers/net/ethernet/marvell/mvmdio.c
@@ -339,11 +339,18 @@ 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))))
-			dev_warn(&pdev->dev,
-				 "unsupported number of clocks, limiting to the first "
-				 __stringify(ARRAY_SIZE(dev->clk)) "\n");
+		{
+			struct clk *extra_clk;
+
+			extra_clk = of_clk_get(pdev->dev.of_node,
+					       ARRAY_SIZE(dev->clk));
+			if (!IS_ERR(extra_clk)) {
+				dev_warn(&pdev->dev,
+					 "unsupported number of clocks, limiting to the first "
+					 __stringify(ARRAY_SIZE(dev->clk)) "\n");
+				clk_put(extra_clk);
+			}
+		}
 
 		if (type == BUS_TYPE_XSMI)
 			orion_mdio_xsmi_set_mdc_freq(bus);
-- 
2.39.5 (Apple Git-154)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help