Skip to contentSkip to conversation

clk: palmas: unprepare clock on provider registration failure

PATCH In review Myeonghun Pak 2 participants 3 messages Jun 23 – Jun 24 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: palmas: unprepare clock on provider registration failure

palmas_clks_init_configure() prepares the clock when an external control pin is configured. If the subsequent of_clk_add_hw_provider() call fails, palmas_clks_probe() returns the error without dropping that prepare reference.

Unprepare the clock on that error path when external control is active, so the probe failure path balances the successful clk_prepare().

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 942d1d674931 ("clk: Add driver for Palmas clk32kg and clk32kgaudio clocks")
---
 drivers/clk/clk-palmas.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/clk-palmas.c +4 -1
index 39049f62db..ab9df2eedb 100644
@@ -265,8 +265,11 @@ static int palmas_clks_probe(struct platform_device *pdev)
 	}
 
 	ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, &cinfo->hw);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(&pdev->dev, "Fail to add clock driver, %d\n", ret);
+		if (cinfo->ext_control_pin)
+			clk_unprepare(cinfo->hw.clk);
+	}
 	return ret;
 }
 
Signature · 1 line
2.47.1
#1 lore raw

Hi Myeonghun,

Thanks for the patch!

Quoted 25 lines · Myeonghun Pak

palmas_clks_init_configure() prepares the clock when an external control pin is configured. If the subsequent of_clk_add_hw_provider() call fails, palmas_clks_probe() returns the error without dropping that prepare reference.

Unprepare the clock on that error path when external control is active, so the probe failure path balances the successful clk_prepare().

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 942d1d674931 ("clk: Add driver for Palmas clk32kg and clk32kgaudio clocks")
---
 drivers/clk/clk-palmas.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/clk-palmas.c +0 -0
index 39049f62db..ab9df2eedb 100644

drivers/clk/clk-palmas.c static int palmas_clks_probe(struct platform_device *pdev) · line 272

Quoted 9 lines
drivers/clk/clk-palmas.c +4 -1
@@ -265,8 +265,11 @@ static int palmas_clks_probe(struct platform_device *pdev)
 	}
 
 	ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, &cinfo->hw);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(&pdev->dev, "Fail to add clock driver, %d\n", ret);
+		if (cinfo->ext_control_pin)
+			clk_unprepare(cinfo->hw.clk);
+	}

The driver currently only calls clk_unprepare() on an error path in palmas_clks_init_configure(). It leaks when the driver is removed.

I think the cleanest approach to fixing this is to convert over to use devm_of_clk_add_hw_provider().

Brian

#2 lore raw

Hi Brian,

Thanks for the review.

Agreed, v1 only handled the provider registration failure path and missed the driver remove path. I will send a v2 converting the provider registration to devm_of_clk_add_hw_provider() and making the external-control clk_prepare() reference device-managed as well.

Best regards,
Myeonghun

2026년 6월 23일 (화) 오후 10:59, Brian Masney <[email protected]>님이 작성:

Quoted 49 lines

Hi Myeonghun,

Thanks for the patch!

Quoted 25 lines · Myeonghun Pak

palmas_clks_init_configure() prepares the clock when an external control pin is configured. If the subsequent of_clk_add_hw_provider() call fails, palmas_clks_probe() returns the error without dropping that prepare reference.

Unprepare the clock on that error path when external control is active, so the probe failure path balances the successful clk_prepare().

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 942d1d674931 ("clk: Add driver for Palmas clk32kg and clk32kgaudio clocks")
---
 drivers/clk/clk-palmas.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/clk-palmas.c +0 -0
index 39049f62db..ab9df2eedb 100644

drivers/clk/clk-palmas.c static int palmas_clks_probe(struct platform_device *pdev) · line 272

Quoted 9 lines
drivers/clk/clk-palmas.c +4 -1
@@ -265,8 +265,11 @@ static int palmas_clks_probe(struct platform_device *pdev)
      }
 
      ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, &cinfo->hw);
-     if (ret < 0)
+     if (ret < 0) {
              dev_err(&pdev->dev, "Fail to add clock driver, %d\n", ret);
+             if (cinfo->ext_control_pin)
+                     clk_unprepare(cinfo->hw.clk);
+     }

The driver currently only calls clk_unprepare() on an error path in palmas_clks_init_configure(). It leaks when the driver is removed.

I think the cleanest approach to fixing this is to convert over to use devm_of_clk_add_hw_provider().

Brian