[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240815005520.1192374-10-sboyd@kernel.org>
Date: Wed, 14 Aug 2024 17:55:15 -0700
From: Stephen Boyd <sboyd@...nel.org>
To: Michael Turquette <mturquette@...libre.com>,
Stephen Boyd <sboyd@...nel.org>
Cc: linux-kernel@...r.kernel.org,
linux-clk@...r.kernel.org,
patches@...ts.linux.dev,
Nuno Sá <nuno.sa@...log.com>,
Sylwester Nawrocki <s.nawrocki@...sung.com>
Subject: [PATCH 09/12] clk: Prevent unregistered clk_hw from being reinserted into clk tree
The clk framework removes the clk_core from the clk tree by deleting the
'child_node' hlist for a clk_hw when it is unregistered in
clk_unregister(). This removes the clk from the clk tree, but a call to
clk_set_parent() will allow the clk to be added right back into the clk
tree, undoing all the work done in clk_unregister() to remove it from
the tree and orphan all descendants. This results in a double hlist
delete as well, because clk_reparent() deletes the 'child_node' hlist
before adding the clk to either the orphan list or the clk tree.
The 'clk_nodrv_ops' have a set_parent clk_op that returns failure, but
that still won't save us even if we fix the clk_reparent() code to
operate on an empty list. That's because we'll reparent the clk back to
the original parent when the clk_op returns an error, effectively
putting the clk back into the clk tree.
Force the number of parents to be zero in clk_unregister() so that
clk_set_parent() can't get past the part where it figures out which
index to use to call the clk_op with.
Cc: Nuno Sá <nuno.sa@...log.com>
Cc: Sylwester Nawrocki <s.nawrocki@...sung.com>
Fixes: fcb0ee6a3d33 ("clk: Implement clk_unregister")
Signed-off-by: Stephen Boyd <sboyd@...nel.org>
---
drivers/clk/clk.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index a0c275e156ad..d99d2d4dd411 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -4611,6 +4611,11 @@ void clk_unregister(struct clk *clk)
clk_core_evict_parent_cache(clk->core);
hlist_del_init(&clk->core->child_node);
+ /*
+ * Prevent clk from being reinserted into the clk tree via
+ * clk_set_parent()
+ */
+ clk->core->num_parents = 0;
if (clk->core->prepare_count)
pr_warn("%s: unregistering prepared clock: %s\n",
--
https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/
https://git.kernel.org/pub/scm/linux/kernel/git/sboyd/spmi.git
Powered by blists - more mailing lists