mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yao Zi <me@ziyao.cc>
To: Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>, Chen-Yu Tsai <wens@csie.org>
Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yao Zi <me@ziyao.cc>, Drew Fustini <fustini@kernel.org>
Subject: [PATCH v2] clk: Avoid DT fetch in possible_parent_show if clk_hw is provided
Date: Thu,  5 Feb 2026 15:42:02 +0000	[thread overview]
Message-ID: <20260205154202.21819-1-me@ziyao.cc> (raw)

When showing a parent for which clk_core_get_parent_by_index fails, we
may try using the parent's global name or the local name. If this fails
either, the parent clock's clock-output-names is fetched through
DT-index.

struct clk_hw pointer takes precedence with DT-index when registering
clocks, thus most drivers only zero the index member of struct
clk_parent_data when providing the parent through struct clk_hw pointer.
If the pointer cannot resovle to a clock, clk_core_get_parent_by_index
will fail as well, in which case possible_parent_show will fetch the
parent's clock-output-names property, treat the unintended, zeroed index
as valid, and yield a misleading name if the clock controller does come
with a clocks property.

Let's add an extra check against the struct clk_hw pointer, and only
perform the DT-index-based fetch if it isn't provided.

Fixes: 2d156b78ce8f ("clk: Fix debugfs clk_possible_parents for clks without parent string names")
Signed-off-by: Yao Zi <me@ziyao.cc>
Tested-by: Drew Fustini <fustini@kernel.org>
---
 drivers/clk/clk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

This was found when fixing the wrong parent description of
clk-th1520-ap.c[1]. Without the patch,

	# cat /sys/kernel/debug/clk/c910/clk_possible_parents
	osc_24m cpu-pll1

The first parent should be c910-i0, provided by an unresolvable struct
clk_hw pointer. osc_24m is the first (and only) parent specified in
devicetree for the clock controller. With the patch,

	# cat /sys/kernel/debug/clk/c910/clk_possible_parents
	(missing) cpu-pll1

[1]: https://lore.kernel.org/linux-riscv/20250705052028.24611-1-ziyao@disroot.org/

Changed from v1:
- Collect tags
- Switch to my new mail address
- Link to v1: https://lore.kernel.org/all/20250705095816.29480-2-ziyao@disroot.org/

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 85d2f2481acf..a9d1aea59689 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3588,7 +3588,7 @@ static void possible_parent_show(struct seq_file *s, struct clk_core *core,
 	} else if (core->parents[i].fw_name) {
 		seq_printf(s, "<%s>(fw)", core->parents[i].fw_name);
 	} else {
-		if (core->parents[i].index >= 0)
+		if (!core->parents[i].hw && core->parents[i].index >= 0)
 			name = of_clk_get_parent_name(core->of_node, core->parents[i].index);
 		if (!name)
 			name = "(missing)";
-- 
2.52.0


             reply	other threads:[~2026-02-05 15:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-05 15:42 Yao Zi [this message]
2026-02-08 13:57 ` Chen-Yu Tsai
2026-02-09 17:47 ` 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=20260205154202.21819-1-me@ziyao.cc \
    --to=me@ziyao.cc \
    --cc=fustini@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.org \
    --cc=wens@csie.org \
    /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

all inboxes | Powered by JetHome®