Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>,
	linux-clk@vger.kernel.org, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v11 3/5] clk: en7523: protect concurrent access to reset and PCI register
Date: Fri, 06 Nov 2026 12:06:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-201377@kernel.org> (raw)
In-Reply-To: <20261106115852.189098-4-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] clk: en7523: NULL dereference in clk_hw_get_dev() before
  registration
--

commit 9029e0297a2815d965ae1a27ae544f0b9a67fb5f
Author: Christian Marangi <ansuelsmth@gmail.com>

clk: en7523: protect concurrent access to reset and PCI register

This commit adds spinlock protection around PCI control and reset register
accesses in the EN7523 clock and reset callbacks.

> diff --git a/drivers/clk/clk-en7523.c b/drivers/clk/clk-en7523.c
> index 2baec734df9fe..e534a5c91e618 100644
> --- a/drivers/clk/clk-en7523.c
> +++ b/drivers/clk/clk-en7523.c
[ ... ]
> @@ -623,12 +666,19 @@ static int en7523_pci_prepare(struct clk_hw *hw)
>  static void en7523_pci_unprepare(struct clk_hw *hw)
>  {
>  	struct en_clk_gate *cg = container_of(hw, struct en_clk_gate, hw);
> +	struct device *dev = clk_hw_get_dev(hw);
>  	void __iomem *np_base = cg->base;
> +	struct en_clk_priv *priv;
> +	unsigned long flags;
>  	u32 val;
>  
> +	priv = dev_get_drvdata(dev);
> +
> +	spin_lock_irqsave(&priv->lock, flags);
>  	val = readl(np_base + REG_PCI_CONTROL);
>  	val &= ~REG_PCI_CONTROL_REFCLK_EN1;
>  	writel(val, np_base + REG_PCI_CONTROL);
> +	spin_unlock_irqrestore(&priv->lock, flags);
>  }
[ ... ]
> @@ -683,12 +748,20 @@ static int en7581_pci_enable(struct clk_hw *hw)
>  static void en7581_pci_disable(struct clk_hw *hw)
>  {
>  	struct en_clk_gate *cg = container_of(hw, struct en_clk_gate, hw);
> +	struct device *dev = clk_hw_get_dev(hw);
>  	void __iomem *np_base = cg->base;
> +	struct en_clk_priv *priv;
> +	unsigned long flags;
>  	u32 val, mask;
>  
> +	priv = dev_get_drvdata(dev);
>  	mask = REG_PCI_CONTROL_REFCLK_EN0 | REG_PCI_CONTROL_REFCLK_EN1;
> +
> +	spin_lock_irqsave(&priv->lock, flags);
>  	val = readl(np_base + REG_PCI_CONTROL);
>  	writel(val & ~mask, np_base + REG_PCI_CONTROL);
> +	spin_unlock_irqrestore(&priv->lock, flags);
> +
>  	usleep_range(1000, 2000);
>  }

[Severity: High]
Does clk_hw_get_dev(hw) dereference a NULL hw->core pointer when
en7523_register_pcie_clk() calls init.ops->unprepare(&cg->hw)?

drivers/clk/clk-en7523.c:en7523_register_pcie_clk() {
	...
	cg->base = np_base;
	cg->hw.init = &init;

	if (init.ops->unprepare)
		init.ops->unprepare(&cg->hw);

	if (devm_clk_hw_register(dev, &cg->hw))
		return NULL;
}

clk_hw_get_dev() returns hw->core->dev, but hw->core is only allocated and
assigned inside devm_clk_hw_register().  Calling init.ops->unprepare()
before registration causes a NULL pointer dereference during probe on SoCs
that set pcie_ops.unprepare to en7523_pci_unprepare() or
en7581_pci_disable().

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

  reply	other threads:[~2026-11-06 12:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 11:58 [PATCH v11 0/5] clk: add support for Airoha AN7583 clock Christian Marangi
2026-11-06 11:58 ` [PATCH v11 1/5] dt-bindings: clock: airoha: Document support for " Christian Marangi
2026-11-06 12:06   ` sashiko-bot
2026-11-06 11:58 ` [PATCH v11 2/5] clk: en7523: use devm variant for clk_hw_register and fixed clock Christian Marangi
2026-11-06 11:58 ` [PATCH v11 3/5] clk: en7523: protect concurrent access to reset and PCI register Christian Marangi
2026-11-06 12:06   ` sashiko-bot [this message]
2026-11-06 11:58 ` [PATCH v11 4/5] clk: en7523: generalize register clocks function Christian Marangi
2026-11-06 11:58 ` [PATCH v11 5/5] clk: en7523: add support for Airoha AN7583 clock Christian Marangi
2026-11-06 12:13   ` sashiko-bot

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=sashiko-outbox-201377@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ansuelsmth@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --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