All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: rockchip: Skip PLL lock wait when GRF regmap is unavailable
@ 2026-12-05  6:40 ` Praneeth Balasubramanian
  0 siblings, 0 replies; 5+ 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] 5+ messages in thread

* [PATCH] clk: rockchip: Skip PLL lock wait when GRF regmap is unavailable
@ 2026-12-05  6:40 ` Praneeth Balasubramanian
  0 siblings, 0 replies; 5+ 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


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

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

* Re: [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
  2026-12-05  8:21     ` Praneeth Balasubramanian
  -1 siblings, 1 reply; 5+ 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] 5+ messages in thread

* Re: [PATCH] clk: rockchip: Skip PLL lock wait when GRF regmap is unavailable
  2026-12-05  6:58 ` sashiko-bot
@ 2026-12-05  8:21     ` Praneeth Balasubramanian
  0 siblings, 0 replies; 5+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05  8:21 UTC (permalink / raw)
  To: sashiko-reviews
  Cc: Stephen Boyd, Brian Masney, Jerome Brunet, Heiko Stuebner,
	linux-clk, linux-arm-kernel, linux-rockchip, linux-kernel

On Sat, 05 Dec 2026 06:58:51 +0000, sashiko-bot@kernel.org wrote:
> [Severity: Medium]
> Can returning 0 immediately here let downstream consumers run on an
> unlocked PLL?

Yes. Please do not apply this version. Without the GRF there is no way
to see the lock bit, so v2 does not let Linux gate these PLLs at all.
It adds rk3066 PLL ops with only .recalc_rate and .is_enabled and uses
them when the GRF is missing. The PLL then stays as the bootloader left
it. I did not use a fixed delay, since I could not find a lock time to
base it on.

v2 also fixes the comment above rockchip_pll_wait_lock(), cites
9be83448951a in Fixes, names rockchip_rk3066_pll_enable() and says that
rockchip,grf is optional in the bindings.

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

* Re: [PATCH] clk: rockchip: Skip PLL lock wait when GRF regmap is unavailable
@ 2026-12-05  8:21     ` Praneeth Balasubramanian
  0 siblings, 0 replies; 5+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05  8:21 UTC (permalink / raw)
  To: sashiko-reviews
  Cc: Stephen Boyd, Brian Masney, Jerome Brunet, Heiko Stuebner,
	linux-clk, linux-arm-kernel, linux-rockchip, linux-kernel

On Sat, 05 Dec 2026 06:58:51 +0000, sashiko-bot@kernel.org wrote:
> [Severity: Medium]
> Can returning 0 immediately here let downstream consumers run on an
> unlocked PLL?

Yes. Please do not apply this version. Without the GRF there is no way
to see the lock bit, so v2 does not let Linux gate these PLLs at all.
It adds rk3066 PLL ops with only .recalc_rate and .is_enabled and uses
them when the GRF is missing. The PLL then stays as the bootloader left
it. I did not use a fixed delay, since I could not find a lock time to
base it on.

v2 also fixes the comment above rockchip_pll_wait_lock(), cites
9be83448951a in Fixes, names rockchip_rk3066_pll_enable() and says that
rockchip,grf is optional in the bindings.

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

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

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

Thread overview: 5+ 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:40 ` Praneeth Balasubramanian
2026-12-05  6:58 ` sashiko-bot
2026-12-05  8:21   ` Praneeth Balasubramanian
2026-12-05  8:21     ` Praneeth Balasubramanian

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.