Linux clock framework development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Miquel Raynal" <miquel.raynal@bootlin.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org,
	linux-clk@vger.kernel.org
Subject: Re: [PATCH v6 08/12] clk: nuvoton: ma35d1: Retrieve HXT/LXT from DT
Date: Wed, 30 Sep 2026 17:40:38 +0000	[thread overview]
Message-ID: <20260930174039.5DB581F0089A@smtp.kernel.org> (raw)
In-Reply-To: <20260930-perso-ma35d1-upstream-clk-v6-8-48937ee6c9bb@bootlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] clk: missing IS_ERR check in ma35d1_clk_gate_parent() causes CCF crash
--

commit 7dc0319906dcefbcabf738c0cfa86cd02109de8b
Author: Miquel Raynal <miquel.raynal@bootlin.com>

clk: nuvoton: ma35d1: Retrieve HXT/LXT from DT

HXT and LXT are crystal oscillator inputs of the clock controller, they
are described in the DT, so retrieve them, in order, and store them in
their respective HXT/LXT hw table entries.

> diff --git a/drivers/clk/nuvoton/clk-ma35d1.c b/drivers/clk/nuvoton/clk-ma35d1.c
> index ceebcbd8c18b3..d955d79abdd2d 100644
> --- a/drivers/clk/nuvoton/clk-ma35d1.c
> +++ b/drivers/clk/nuvoton/clk-ma35d1.c

[ ... ]

> @@ -191,6 +192,15 @@ static struct clk_hw *ma35d1_clk_gate(struct device *dev, const char *name, cons
>  				    reg, shift, 0, &ma35d1_lock);
>  }
>  
> +static struct clk_hw *ma35d1_clk_gate_parent(struct device *dev, const char *name,
> +					     struct clk_hw *parent,
> +					     void __iomem *reg, u8 shift)
> +{
> +	return devm_clk_hw_register_gate_parent_hw(dev, name, parent,
> +						   CLK_SET_RATE_PARENT,
> +						   reg, shift, 0, &ma35d1_lock);
> +}
> +

[Severity: High]
Does this wrapper need to check if the parent clock is valid before passing
it to the core clock framework?

Looking at ma35d1_clocks_probe() below, if the fallback clock creation via
ma35d1_clk_fixed() fails, it returns an ERR_PTR which is stored in hws[LXT].

[ ... ]

> @@ -240,12 +252,27 @@ static int ma35d1_clocks_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>  
> -	hws[HXT] = ma35d1_clk_fixed("hxt", 24000000);
> -	hws[HXT_GATE] = ma35d1_clk_gate(dev, "hxt_gate", "hxt",
> -					clk_base + REG_CLK_PWRCTL, 0);
> -	hws[LXT] = ma35d1_clk_fixed("lxt", 32768);
> -	hws[LXT_GATE] = ma35d1_clk_gate(dev, "lxt_gate", "lxt",
> -					clk_base + REG_CLK_PWRCTL, 1);
> +	num_clks = devm_clk_bulk_get_all(dev, &clks);
> +	if (num_clks < 0)
> +		return num_clks;
> +
> +	if (!num_clks) {
> +		dev_err(dev, "missing crystal input clocks\n");
> +		return -ENODEV;
> +	}
> +
> +	hws[HXT] = __clk_get_hw(clks[0].clk);
> +
> +	if (num_clks > 1)
> +		hws[LXT] = __clk_get_hw(clks[1].clk);
> +	else
> +		/* Old DTs do not describe the low-speed crystal */
> +		hws[LXT] = ma35d1_clk_fixed("lxt", 32768);
> +
> +	hws[HXT_GATE] = ma35d1_clk_gate_parent(dev, "hxt_gate", hws[HXT],
> +					       clk_base + REG_CLK_PWRCTL, 0);
> +	hws[LXT_GATE] = ma35d1_clk_gate_parent(dev, "lxt_gate", hws[LXT],
> +					       clk_base + REG_CLK_PWRCTL, 1);

When hws[LXT] containing an ERR_PTR is passed to ma35d1_clk_gate_parent(),
it gets sent directly to devm_clk_hw_register_gate_parent_hw().

Because the Common Clock Framework does not validate parent arrays for error
pointers, this will cause a kernel panic when the core later resolves the
parent map and dereferences the invalid memory.

Could we add an IS_ERR() check either around the fixed clock allocation
or inside ma35d1_clk_gate_parent()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260930-perso-ma35d1-upstream-clk-v6-0-48937ee6c9bb@bootlin.com?part=8

  reply	other threads:[~2026-09-30 17:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 17:24 [PATCH v6 00/12] clk: nuvoton: ma35d1: Fix mux parenting and peripheral clock rates Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 01/12] clk: nuvoton: ma35d1: Keep the clock count in the driver Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 02/12] dt-bindings: clock: ma35d1: Document the missing crystal inputs Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 03/12] dt-bindings: clock: ma35d1: Drop CLK_MAX_IDX define Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 04/12] dt-bindings: clock: ma35d1: Add missing WDT/WWDT parent clocks Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 05/12] clk: nuvoton: " Miquel Raynal
2026-10-01  9:44   ` Jerome Brunet
2026-10-01 10:28     ` Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 06/12] clk: nuvoton: ma35d1: Use clk_hw pointers as mux parents Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 07/12] clk: nuvoton: ma35d1: Avoid possible error pointer dereferencing Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 08/12] clk: nuvoton: ma35d1: Retrieve HXT/LXT from DT Miquel Raynal
2026-09-30 17:40   ` sashiko-bot [this message]
2026-10-01  9:36   ` Jerome Brunet
2026-10-01 16:12     ` Miquel Raynal
2026-10-02  8:16       ` Jerome Brunet
2026-09-30 17:24 ` [PATCH v6 09/12] clk: nuvoton: ma35d1: Reparent the gates correctly Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 10/12] clk: nuvoton: ma35d1: Reparent SYSPLL correctly Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 11/12] arm64: dts: nuvoton: ma35d1: Drop HXT clock output name Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 12/12] arm64: dts: nuvoton: ma35d1: Add LXT crystal and clock-names Miquel Raynal
2026-10-01  9:53 ` (subset) [PATCH v6 00/12] clk: nuvoton: ma35d1: Fix mux parenting and peripheral clock rates Jerome Brunet

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=20260930174039.5DB581F0089A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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