Linux clock framework development
 help / color / mirror / Atom feed
* [PATCH] clk: rockchip: Skip PLL lock wait when GRF regmap is unavailable
@ 2026-12-05  6:40 Praneeth Balasubramanian
  2026-12-05  6:58 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05  6:40 UTC (permalink / raw)
  To: Stephen Boyd, Brian Masney, Jerome Brunet, Heiko Stuebner
  Cc: Praneeth Balasubramanian, stable, linux-clk, linux-arm-kernel,
	linux-rockchip, linux-kernel

When the DT node for a CRU has no rockchip,grf phandle,
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_pll_enable()
calls rockchip_pll_wait_lock(), which passes the error pointer to
regmap_read_poll_timeout().

The only way to reach this state is a DT error, so the harm is limited
to robustness against a broken DT. Add an IS_ERR() check on the GRF
regmap in rockchip_pll_wait_lock() and return 0 when it is missing.
Without the GRF the lock bit cannot be polled, so the PLL is assumed to
lock after the powerdown bit is cleared. The set_rate path that also
uses the GRF is already excluded by the ops selection.

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

Fixes: 90c590254051 ("clk: rockchip: add clock type for pll clocks and pll used on rk3066")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---

Notes:
    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 and
    checked against the source with Claude Opus 5.5. 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 | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
index d371c66800df..88bced1915e6 100644
--- a/drivers/clk/rockchip/clk-pll.c
+++ b/drivers/clk/rockchip/clk-pll.c
@@ -95,6 +95,9 @@ static int rockchip_pll_wait_lock(struct rockchip_clk_pll *pll)
 	unsigned int val;
 	int ret;
 
+	if (IS_ERR(grf))
+		return 0;
+
 	ret = regmap_read_poll_timeout(grf, pll->lock_offset, val,
 				       val & BIT(pll->lock_shift), 0, 1000);
 	if (ret)

base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] clk: rockchip: Skip PLL lock wait when GRF regmap is unavailable
  2026-12-05  6:40 [PATCH] clk: rockchip: Skip PLL lock wait when GRF regmap is unavailable Praneeth Balasubramanian
@ 2026-12-05  6:58 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05  6:58 UTC (permalink / raw)
  To: Praneeth Balasubramanian; +Cc: linux-clk

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] clk: rockchip: rockchip_pll_wait_lock() skips lock delay when
  GRF is missing
- [Low] clk: rockchip: stale comment above rockchip_pll_wait_lock()
- [Low] clk: rockchip: Fixes tag cites 90c590254051 instead of
  9be83448951a
- [Low] clk: rockchip: inaccurate function name and DT claim in commit
  message
--

commit d3bc6bdc7581ec5ff20f428e879a18138c494ca0
Author: Praneeth Balasubramanian <praneethb2002@gmail.com>

> clk: rockchip: Skip PLL lock wait when GRF regmap is unavailable
>
> When the DT node for a CRU has no rockchip,grf phandle,
> 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_pll_enable()
> calls rockchip_pll_wait_lock(), which passes the error pointer to
> regmap_read_poll_timeout().
>
> The only way to reach this state is a DT error, so the harm is limited
> to robustness against a broken DT. Add an IS_ERR() check on the GRF
> regmap in rockchip_pll_wait_lock() and return 0 when it is missing.
> Without the GRF the lock bit cannot be polled, so the PLL is assumed to
> lock after the powerdown bit is cleared. The set_rate path that also
> uses the GRF is already excluded by the ops selection.

[Severity: Low]
Two small inaccuracies in the commit description: the callback is named
rockchip_rk3066_pll_enable(), not rockchip_pll_enable().  Also, omitting
rockchip,grf is not a DT error: the RK3188, RK3288, and RK3368 CRU
bindings all list rockchip,grf as optional, so a schema-valid DT can hit
this path at boot.

> This was found by an LLM-based audit that checks code against the rules
> stated in kernel comments.
>
> Fixes: 90c590254051 ("clk: rockchip: add clock type for pll clocks and pll used on rk3066")
> Cc: stable@vger.kernel.org
> Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>

[Severity: Low]
Should this Fixes: tag cite 9be83448951a ("clk: rockchip: add
pll_wait_lock for pll_enable") instead?  In 90c590254051 ("clk: rockchip:
add clock type for pll clocks and pll used on rk3066"),
rockchip_pll_wait_lock() was only called from
rockchip_rk3066_pll_set_rate() after checking IS_ERR(grf); 9be83448951a
("clk: rockchip: add pll_wait_lock for pll_enable") added the unguarded
call in rockchip_rk3066_pll_enable().

> diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
> index d371c66800df6..88bced1915e6b 100644
> --- a/drivers/clk/rockchip/clk-pll.c
> +++ b/drivers/clk/rockchip/clk-pll.c
> @@ -95,6 +95,9 @@ static int rockchip_pll_wait_lock(struct rockchip_clk_pll *pll)
>  	unsigned int val;
>  	int ret;
>  
> +	if (IS_ERR(grf))
> +		return 0;

[Severity: Medium]
Can returning 0 immediately here let downstream consumers run on an
unlocked PLL?

When ctx->grf is unavailable, rockchip_rk3066_pll_clk_norate_ops still
installs rockchip_rk3066_pll_enable() and rockchip_rk3066_pll_disable().
An unprotected PLL such as npll on RK3288 can be powered down via
RK3066_PLLCON3_PWRDOWN when its consumers disable it; on re-enable,
rockchip_rk3066_pll_enable() clears PWRDOWN and relies solely on
rockchip_pll_wait_lock() to wait for stabilization, risking peripheral
malfunction or bus hangs if the clock is used before lock.

Consider either waiting a conservative fixed delay when grf is unavailable
or omitting .enable/.disable when IS_ERR(ctx->grf) so PLLs are not powered
down without a lock check.

[Severity: Low]
The comment immediately above rockchip_pll_wait_lock() now contradicts
this change:

drivers/clk/rockchip/clk-pll.c (above rockchip_pll_wait_lock()):
/*
 * Wait for the pll to reach the locked state.
 * The calling set_rate function is responsible for making sure the
 * grf regmap is available.
 */

Because rockchip_pll_wait_lock() now handles IS_ERR(grf) directly and is
also called by rockchip_rk3066_pll_enable(), this comment should be
updated to reflect the actual contract when GRF is unavailable.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205064016.2525825-1-praneethb2002@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-05  6:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  6:40 [PATCH] clk: rockchip: Skip PLL lock wait when GRF regmap is unavailable Praneeth Balasubramanian
2026-12-05  6:58 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox