Linux Tegra architecture development
 help / color / mirror / Atom feed
* [PATCH] clk: tegra: tegra124: Stop clock init when the preamble fails
@ 2026-12-05  6:40 Praneeth Balasubramanian
  0 siblings, 0 replies; only message in thread
From: Praneeth Balasubramanian @ 2026-12-05  6:40 UTC (permalink / raw)
  To: Prashant Gaikwad, Stephen Boyd, Brian Masney, Jerome Brunet,
	Thierry Reding, Jonathan Hunter
  Cc: Praneeth Balasubramanian, stable, linux-clk, linux-tegra,
	linux-kernel

tegra124_132_clock_init_pre() returns early when it cannot map the CAR or
PMC registers, cannot allocate the clock table, or cannot set up the
oscillator. It returns void, so tegra124_clock_init() and
tegra132_clock_init() run tegra124_132_clock_init_post() anyway. The
postamble then uses a NULL clks table or a NULL clk_base. An early init
failure turns into a NULL pointer dereference instead of a boot error.

Return an error code from the preamble and skip the rest of the init when
it fails. The Tegra20, Tegra30, Tegra114 and Tegra210 init functions
already stop at the same points.

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

Fixes: 08acae34e8da ("clk: tegra: Add support for the Tegra132 CAR IP block")
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,
    then checked against the source and partly rewritten 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;
    arm64 defconfig; arm multi_v7_defconfig), clang 23. checkpatch.pl is
    clean. Not runtime-tested, and there is no reproducer. I do not have
    this hardware.

 drivers/clk/tegra/clk-tegra124.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/clk/tegra/clk-tegra124.c b/drivers/clk/tegra/clk-tegra124.c
index 6c46592d794e..5dc1d9ae9f14 100644
--- a/drivers/clk/tegra/clk-tegra124.c
+++ b/drivers/clk/tegra/clk-tegra124.c
@@ -1451,9 +1451,10 @@ static void __init tegra132_clock_apply_init_table(void)
  *
  * Register most of the clocks controlled by the CAR IP block.
  * Everything in this function should be common to Tegra124 and Tegra132.
- * No return value.
+ *
+ * Return: 0 on success or a negative error code.
  */
-static void __init tegra124_132_clock_init_pre(struct device_node *np)
+static int __init tegra124_132_clock_init_pre(struct device_node *np)
 {
 	struct device_node *node;
 	u32 plld_base;
@@ -1461,14 +1462,14 @@ static void __init tegra124_132_clock_init_pre(struct device_node *np)
 	clk_base = of_iomap(np, 0);
 	if (!clk_base) {
 		pr_err("ioremap tegra124/tegra132 CAR failed\n");
-		return;
+		return -ENOMEM;
 	}
 
 	node = of_find_matching_node(NULL, pmc_match);
 	if (!node) {
 		pr_err("Failed to find pmc node\n");
 		WARN_ON(1);
-		return;
+		return -ENODEV;
 	}
 
 	pmc_base = of_iomap(node, 0);
@@ -1476,18 +1477,18 @@ static void __init tegra124_132_clock_init_pre(struct device_node *np)
 	if (!pmc_base) {
 		pr_err("Can't map pmc registers\n");
 		WARN_ON(1);
-		return;
+		return -ENOMEM;
 	}
 
 	clks = tegra_clk_init(clk_base, TEGRA124_CLK_CLK_MAX,
 			      TEGRA124_CAR_BANK_COUNT);
 	if (!clks)
-		return;
+		return -ENOMEM;
 
 	if (tegra_osc_clk_init(clk_base, tegra124_clks, tegra124_input_freq,
 			       ARRAY_SIZE(tegra124_input_freq), 1, &osc_freq,
 			       &pll_ref_freq) < 0)
-		return;
+		return -EINVAL;
 
 	tegra_fixed_clk_init(tegra124_clks);
 	tegra124_pll_init(clk_base, pmc_base);
@@ -1500,6 +1501,8 @@ static void __init tegra124_132_clock_init_pre(struct device_node *np)
 	plld_base = readl(clk_base + PLLD_BASE);
 	plld_base &= ~BIT(25);
 	writel(plld_base, clk_base + PLLD_BASE);
+
+	return 0;
 }
 
 static struct clk *tegra124_clk_src_onecell_get(struct of_phandle_args *clkspec,
@@ -1561,7 +1564,9 @@ static void __init tegra124_132_clock_init_post(struct device_node *np)
  */
 static void __init tegra124_clock_init(struct device_node *np)
 {
-	tegra124_132_clock_init_pre(np);
+	if (tegra124_132_clock_init_pre(np))
+		return;
+
 	tegra_clk_apply_init_table = tegra124_clock_apply_init_table;
 	tegra124_132_clock_init_post(np);
 }
@@ -1579,7 +1584,8 @@ static void __init tegra124_clock_init(struct device_node *np)
  */
 static void __init tegra132_clock_init(struct device_node *np)
 {
-	tegra124_132_clock_init_pre(np);
+	if (tegra124_132_clock_init_pre(np))
+		return;
 
 	/*
 	 * On Tegra132, these clocks are controlled by the

base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05  6:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  6:40 [PATCH] clk: tegra: tegra124: Stop clock init when the preamble fails Praneeth Balasubramanian

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