Skip to contentSkip to conversation

clk: devres: Skip cleanup action for absent optional clocks

PATCH Applied Baek Kyu, Kim 2 participants 3 messages Oct 18 – Nov 2 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: devres: Skip cleanup action for absent optional clocks

devm_clk_get_optional_enabled_with_rate() registers a disable/unprepare action even when the optional lookup returns NULL. If allocating the action fails, the error path calls devm_clk_put(dev, NULL), triggering warnings in devm_clk_match() and devm_clk_put().

Return NULL after the lookup to skip the unnecessary action registration. The state allocated by devm_clk_get_optional() is released when the device is detached.

Fixes 0d4d262c1664 ("clk: devres: fix cleanup in devm_clk_get_optional_enabled_with_rate()")

---
Tested with KUnit under ARM64 QEMU using a test clock provider and failslab. Failing the action allocation for an absent clock triggers two warnings before the fix; the fix skips that allocation. All nine tests pass with the fix, including cleanup and error paths for a registered clock. The fix was not tested on physical hardware.

 drivers/clk/clk-devres.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clk-devres.c +2 -2
index 4cc3863bd7da..35fa34a961e4 100644
@@ -112,8 +112,8 @@ struct clk *devm_clk_get_optional_enabled_with_rate(struct device *dev,
 	int ret;
 
 	clk = devm_clk_get_optional(dev, id);
-	if (IS_ERR(clk))
-		return ERR_CAST(clk);
+	if (IS_ERR_OR_NULL(clk))
+		return clk;
 
 	ret = clk_set_rate(clk, rate);
 	if (ret)

base-commit: 58161ead29e50d70a317ea26b472e0c7508e69da

Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Kim

devm_clk_get_optional_enabled_with_rate() registers a disable/unprepare action even when the optional lookup returns NULL. If allocating the action fails, the error path calls devm_clk_put(dev, NULL), triggering warnings in devm_clk_match() and devm_clk_put().

Return NULL after the lookup to skip the unnecessary action registration. The state allocated by devm_clk_get_optional() is released when the device is detached.

[...]

Signature · 1 line
Jerome