[PATCH] clk: Reject positive return values from init callbacks
From: yong . liu
Date: Tue Sep 22 2026 - 23:59:35 EST
Clock init callbacks must return zero on success or a negative error code
on failure. If a callback returns a positive value, __clk_core_init()
already takes its failure path and __clk_register() releases the clock
before returning ERR_PTR(ret).
However, a positive value encoded by ERR_PTR() is not recognized by
IS_ERR(). Consequently, clk_register() returns an invalid pointer that
passes the caller's error check, while clk_hw_register() and
of_clk_hw_register() report success through PTR_ERR_OR_ZERO() despite
registration having failed.
Convert positive init return values to -EINVAL before taking the failure
path. This makes the registration failure detectable through the public
registration interfaces while preserving valid negative error codes.
Signed-off-by: yong.liu <binary_world@xxxxxxx>
---
drivers/clk/clk.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -4053,6 +4053,8 @@ static int __clk_core_init(struct clk_core *core)
*/
if (core->ops->init) {
ret = core->ops->init(core->hw);
+ if (ret > 0)
+ ret = -EINVAL;
if (ret)
goto out;
}