[PATCH] clk: devres: Skip cleanup action for absent optional clocks
From: Baek Kyu, Kim
Date: Sun Oct 18 2026 - 02:30:24 EST
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()")
Signed-off-by: Baek Kyu, Kim <pocj8ur4in@xxxxxxxxx>
---
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(-)
diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c
index 4cc3863bd7da..35fa34a961e4 100644
--- a/drivers/clk/clk-devres.c
+++ b/drivers/clk/clk-devres.c
@@ -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
--
2.55.0