clk: devres: Skip cleanup action for absent optional clocks
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.
---
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
@@ -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
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 callsdevm_clk_put(dev, NULL), triggering warnings indevm_clk_match()anddevm_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
Jerome Brunet
AppliedApplied to clk/linux.git (clk-pile), thanks!
[1/1] clk: devres: Skip cleanup action for absent optional clocks
https://git.kernel.org/clk/linux/c/8c30b4bf0868
Best regards,
--
Jerome