public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org,
	patches@lists.linux.dev, "Nuno Sá" <nuno.sa@analog.com>,
	"Sylwester Nawrocki" <s.nawrocki@samsung.com>
Subject: [PATCH 09/12] clk: Prevent unregistered clk_hw from being reinserted into clk tree
Date: Wed, 14 Aug 2024 17:55:15 -0700	[thread overview]
Message-ID: <20240815005520.1192374-10-sboyd@kernel.org> (raw)
In-Reply-To: <20240815005520.1192374-1-sboyd@kernel.org>

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@analog.com>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Fixes: fcb0ee6a3d33 ("clk: Implement clk_unregister")
Signed-off-by: Stephen Boyd <sboyd@kernel.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


  parent reply	other threads:[~2024-08-15  0:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-15  0:55 [PATCH 00/12] clk: Unit test clk unregistration paths Stephen Boyd
2024-08-15  0:55 ` [PATCH 01/12] clk: Fix clk not being unlinked from consumers list Stephen Boyd
2024-08-15  0:55 ` [PATCH 02/12] clk: test: Introduce clk_hw_unregister_kunit() Stephen Boyd
2024-08-15  0:55 ` [PATCH 03/12] clk: test: Introduce clk_put_kunit() Stephen Boyd
2024-08-15  0:55 ` [PATCH 04/12] clk: Add tests for unregistering clk_hw and using consumer APIs Stephen Boyd
2024-08-15  0:55 ` [PATCH 05/12] clk: Fail phase APIs after clk_hw is unregistered Stephen Boyd
2024-08-15  0:55 ` [PATCH 06/12] clk: Test clk_get_phase() behavior " Stephen Boyd
2024-08-15  0:55 ` [PATCH 07/12] clk: Fail duty cycle APIs " Stephen Boyd
2024-08-15  0:55 ` [PATCH 08/12] clk: Test clk_set_duty_cycle() behavior " Stephen Boyd
2024-08-15  0:55 ` Stephen Boyd [this message]
2024-08-15  0:55 ` [PATCH 10/12] clk: Test clk_set_parent() " Stephen Boyd
2024-08-15  0:55 ` [PATCH 11/12] clk: Test parent/clk flags combos while unregistering a clk_hw Stephen Boyd
2024-08-15  0:55 ` [PATCH 12/12] WIP: clk: Test behavior of children clks after a parent is unregistered Stephen Boyd

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240815005520.1192374-10-sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=nuno.sa@analog.com \
    --cc=patches@lists.linux.dev \
    --cc=s.nawrocki@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox