[PATCH] clk: Fix referring to wrong pointer in devm_clk_release()

From: Kunihiko Hayashi
Date: Wed Jun 22 2022 - 21:02:31 EST


At bind phase, __devm_clk_get() calls devres_alloc() to allocate devres,
and dr->data is treated as a variable "state".

At unbind phase, release_nodes() calls devm_clk_release() specified by
devres_alloc().

The argument "res" of devm_clk_release() is dr->data, and this entity is
"state", however in devm_clk_release(), "*res" is treated as "state",
resulting in pointer inconsistency.

Unbinding a driver caused a panic.

Unable to handle kernel execute from non-executable memory
at virtual address ffff000100236810
...
pc : 0xffff000100236810
lr : devm_clk_release+0x6c/0x9c
...
Call trace:
0xffff000100236810
release_nodes+0xb0/0x150
devres_release_all+0x94/0xf8
device_unbind_cleanup+0x20/0x70
device_release_driver_internal+0x114/0x1a0
device_driver_detach+0x20/0x30

Cc: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx>
Fixes: abae8e57e49a ("clk: generalize devm_clk_get() a bit")
Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@xxxxxxxxxxxxx>
---
drivers/clk/clk-devres.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c
index 43ccd20e0298..1f37ed7ad395 100644
--- a/drivers/clk/clk-devres.c
+++ b/drivers/clk/clk-devres.c
@@ -11,7 +11,7 @@ struct devm_clk_state {

static void devm_clk_release(struct device *dev, void *res)
{
- struct devm_clk_state *state = *(struct devm_clk_state **)res;
+ struct devm_clk_state *state = (struct devm_clk_state *)res;

if (state->exit)
state->exit(state->clk);
--
2.25.1