Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Karl Mehltretter" <kmehltretter@gmail.com>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH] cpufreq: imx6q: fix devres accumulation across driver rebind
Date: Thu, 06 Aug 2026 05:17:06 +0000	[thread overview]
Message-ID: <20260806051707.01ED21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806050902.90550-1-kmehltretter@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The file-scope static variable `soc_opp_count` is never reset to 0 across driver unbind/rebind or deferred probe cycles, leading to a severe out-of-bounds write array overflow.
--

--- Patch [1]: [PATCH] cpufreq: imx6q: fix devres accumulation across driver rebind ---
commit d8bcb5a2ed1157b0b23fd4c657a9fd392c54309b
Author: Karl Mehltretter <kmehltretter@gmail.com>

cpufreq: imx6q: fix devres accumulation across driver rebind

This commit fixes a memory leak caused by devres accumulation during driver
unbind and rebind cycles. It changes the memory allocation of imx6_soc_volt
to tie its lifetime to the platform device, and clears the file-scope pointer
in the remove and probe-failure paths.

> diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
> index e93697d3edfd9..8110c95059e0e 100644
> --- a/drivers/cpufreq/imx6q-cpufreq.c
> +++ b/drivers/cpufreq/imx6q-cpufreq.c

[ ... ]

> @@ -506,6 +507,7 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
>  static void imx6q_cpufreq_remove(struct platform_device *pdev)
>  {
>  	cpufreq_unregister_driver(&imx6q_cpufreq_driver);
> +	imx6_soc_volt = NULL;

[Severity: High]
This is a pre-existing issue, but since this patch explicitly tests and 
fixes rebind behavior, should soc_opp_count also be reset to 0 here?

The file-scope static variable soc_opp_count is never reset to 0 across 
driver unbind/rebind or deferred probe cycles. 

In imx6q_cpufreq_probe(), the loop increments soc_opp_count:

	for (j = 0; j < num; j++) {
		val = prop->value;
		for (i = 0; i < nr / 2; i++) {
			unsigned long freq = be32_to_cpup(val++);
			unsigned long volt = be32_to_cpup(val++);
			if (freq_table[j].frequency == freq) {
				imx6_soc_volt[soc_opp_count++] = volt;
				break;
			}
		}
	}

On subsequent probes (e.g. after the unbind/rebind cycle you tested), it 
resumes counting from its previous value instead of 0. Since imx6_soc_volt 
is newly allocated with size 'num', this will write beyond the bounds of 
the array, causing memory corruption.

Does the driver need to reset soc_opp_count to 0 during removal and on the 
error paths in probe?

>  	dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
>  	dev_pm_opp_of_remove_table(cpu_dev);
>  	regulator_put(arm_reg);

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

  reply	other threads:[~2026-08-06  5:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06  5:09 [PATCH] cpufreq: imx6q: fix devres accumulation across driver rebind Karl Mehltretter
2026-08-06  5:17 ` sashiko-bot [this message]
2026-08-06  6:12 ` Viresh Kumar

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=20260806051707.01ED21F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=kmehltretter@gmail.com \
    --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