All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wentao Liang" <vulab@iscas.ac.cn>
Cc: linux-clk@vger.kernel.org
Subject: Re: [PATCH] clk: samsung: Fix parent clock reference leak on enable failure
Date: Tue, 15 Sep 2026 06:03:54 +0000	[thread overview]
Message-ID: <20260915060354.D61191F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260915055343.1730045-1-vulab@iscas.ac.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] clk: samsung: use-after-free in suspend/resume due to dangling data->clk
--

commit 24f91a497fb993e31220f4d3d97ab6c013f81744
Author: Wentao Liang <vulab@iscas.ac.cn>

clk: samsung: Fix parent clock reference leak on enable failure

In exynos_arm64_enable_bus_clk(), when dev is NULL the parent clock is
obtained with of_clk_get_by_name() and then handed to
clk_prepare_enable(). On the enable failure path the function returns
directly without clk_put(), leaking the consumer reference.

Store the clk_prepare_enable() return value and release the reference
with clk_put() before returning on failure.

> diff --git a/drivers/clk/samsung/clk-exynos-arm64.c b/drivers/clk/samsung/clk-exynos-arm64.c
> index 35d4de233cc1b..05c4a15dfe993 100644
> --- a/drivers/clk/samsung/clk-exynos-arm64.c
> +++ b/drivers/clk/samsung/clk-exynos-arm64.c
> @@ -149,6 +149,7 @@ static int __init exynos_arm64_enable_bus_clk(struct device *dev,
>  		struct device_node *np, const struct samsung_cmu_info *cmu)
>  {
>  	struct clk *parent_clk;
> +	int ret;
>  
>  	if (!cmu->clk_name)
>  		return 0;

[ ... ]

> @@ -167,7 +168,11 @@ static int __init exynos_arm64_enable_bus_clk(struct device *dev,
>  	if (IS_ERR(parent_clk))
>  		return PTR_ERR(parent_clk);
>  
> -	return clk_prepare_enable(parent_clk);
> +	ret = clk_prepare_enable(parent_clk);
> +	if (ret)
> +		clk_put(parent_clk);
> +
> +	return ret;
>  }

[Severity: High]
Does this error path leave a dangling pointer in the device's PM data
structure?

Earlier in exynos_arm64_enable_bus_clk(), if dev is not NULL, the parent_clk
is saved to data->clk:

drivers/clk/samsung/clk-exynos-arm64.c:exynos_arm64_enable_bus_clk() {
	...
	if (dev) {
		...
		parent_clk = clk_get(dev, cmu->clk_name);
		data = dev_get_drvdata(dev);
		if (data)
			data->clk = parent_clk;
	}
	...
}

When clk_prepare_enable() fails, the caller exynos_arm64_register_cmu_pm()
intentionally ignores the failure and proceeds with initialization:

drivers/clk/samsung/clk-exynos-arm64.c:exynos_arm64_register_cmu_pm() {
	...
	ret = exynos_arm64_enable_bus_clk(dev, NULL, cmu);
	if (ret)
		dev_err(dev, "%s: could not enable bus clock %s; err = %d\n",
		        __func__, cmu->clk_name, ret);
	...
}

During system suspend, exynos_arm64_cmu_suspend() unconditionally references
data->clk:

drivers/clk/samsung/clk-exynos-arm64.c:exynos_arm64_cmu_suspend() {
	...
	clk_disable_unprepare(data->clk);
}

Could this cause a use-after-free and a kernel panic during system suspend if
the clock enablement fails during probe, since the newly added clk_put() frees
the clock object but data->clk is never cleared?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260915055343.1730045-1-vulab@iscas.ac.cn?part=1

      reply	other threads:[~2026-09-15  6:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15  5:53 [PATCH] clk: samsung: Fix parent clock reference leak on enable failure Wentao Liang
2026-09-15  6:03 ` sashiko-bot [this message]

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=20260915060354.D61191F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vulab@iscas.ac.cn \
    /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 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.