Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Stephen Boyd <sboyd@kernel.org>,
	Brian Masney <bmasney+clk@redhat.com>,
	Jerome Brunet <jbrunet+clk@baylibre.com>,
	Heiko Stuebner <heiko@sntech.de>
Cc: Praneeth Balasubramanian <praneethb2002@gmail.com>,
	stable@vger.kernel.org, linux-clk@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] clk: rockchip: Do not gate rk3066 PLLs when the GRF regmap is missing
Date: Sat,  5 Dec 2026 00:31:17 -0800	[thread overview]
Message-ID: <20261205083117.2603316-1-praneethb2002@gmail.com> (raw)

The rockchip,grf property of the RK3188, RK3288 and RK3368 CRU nodes is
optional in the DT bindings. When it is absent,
syscon_regmap_lookup_by_phandle() stores an error pointer in ctx->grf.
For rk3066-type PLLs the registration code then selects the no-rate ops.
Those ops still install the .enable callback.
rockchip_rk3066_pll_enable() calls rockchip_pll_wait_lock(), which
passes the error pointer to regmap_read_poll_timeout(). All in-tree DTs
set the property, so this needs an out-of-tree DT.

The lock bit lives in the GRF. Without it there is no way to know when a
PLL is locked after power up. So do not power these PLLs up or down at
all. Add ops with only .recalc_rate and .is_enabled and select them when
the GRF is missing. The PLL then stays in the state the bootloader left
it in. The set_rate path that also uses the GRF was already excluded.

rockchip_pll_wait_lock() used to be reached only from the set_rate and
init callbacks, which are not installed when the GRF is missing. Commit
9be83448951a ("clk: rockchip: add pll_wait_lock for pll_enable") added
the call in the enable path.

This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.

Fixes: 9be83448951a ("clk: rockchip: add pll_wait_lock for pll_enable")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    Changes in v2:
    - Reworked. v1 returned 0 from rockchip_pll_wait_lock() when the GRF is
      missing, so a PLL could be used before it locked again after a
      re-enable (Sashiko). v2 installs no enable, disable or rate callbacks
      without the GRF, so Linux never gates these PLLs. Fixes now names
      9be83448951a. The changelog has the right function name and says the
      property is optional in the bindings.
    
    v1: https://lore.kernel.org/all/20261205064016.2525825-1-praneethb2002@gmail.com/
    
    This was found by an LLM-based audit, part of research at UCSB SecLab.
    An LLM turned a kernel comment into a rule, and three LLM votes checked
    the code against it. The fix and changelog were drafted with GLM-5.3,
    then checked against the source and partly rewritten with Claude Opus
    5.5. The v2 changes were made with Claude Opus 5.5 after it checked the
    Sashiko review against the source. I reviewed the patch and take
    responsibility for it.
    
    Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
    clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
    reproducer. I do not have this hardware.

 drivers/clk/rockchip/clk-pll.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
index d371c66800df..5f60516b2791 100644
--- a/drivers/clk/rockchip/clk-pll.c
+++ b/drivers/clk/rockchip/clk-pll.c
@@ -86,8 +86,7 @@ static int rockchip_pll_determine_rate(struct clk_hw *hw,
 
 /*
  * Wait for the pll to reach the locked state.
- * The calling set_rate function is responsible for making sure the
- * grf regmap is available.
+ * The caller is responsible for making sure the grf regmap is available.
  */
 static int rockchip_pll_wait_lock(struct rockchip_clk_pll *pll)
 {
@@ -575,6 +574,15 @@ static const struct clk_ops rockchip_rk3066_pll_clk_norate_ops = {
 	.is_enabled = rockchip_rk3066_pll_is_enabled,
 };
 
+/*
+ * Without the GRF the lock bit cannot be read, so the PLL is left as the
+ * bootloader set it: it is never powered down, powered up or reprogrammed.
+ */
+static const struct clk_ops rockchip_rk3066_pll_clk_nogrf_ops = {
+	.recalc_rate = rockchip_rk3066_pll_recalc_rate,
+	.is_enabled = rockchip_rk3066_pll_is_enabled,
+};
+
 static const struct clk_ops rockchip_rk3066_pll_clk_ops = {
 	.recalc_rate = rockchip_rk3066_pll_recalc_rate,
 	.determine_rate = rockchip_pll_determine_rate,
@@ -1161,7 +1169,9 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
 			init.ops = &rockchip_rk3036_pll_clk_ops;
 		break;
 	case pll_rk3066:
-		if (!pll->rate_table || IS_ERR(ctx->grf))
+		if (IS_ERR(ctx->grf))
+			init.ops = &rockchip_rk3066_pll_clk_nogrf_ops;
+		else if (!pll->rate_table)
 			init.ops = &rockchip_rk3066_pll_clk_norate_ops;
 		else
 			init.ops = &rockchip_rk3066_pll_clk_ops;

base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
-- 
2.25.1


                 reply	other threads:[~2026-12-05  8:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261205083117.2603316-1-praneethb2002@gmail.com \
    --to=praneethb2002@gmail.com \
    --cc=bmasney+clk@redhat.com \
    --cc=heiko@sntech.de \
    --cc=jbrunet+clk@baylibre.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=sboyd@kernel.org \
    --cc=stable@vger.kernel.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