Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andreas Kemnade" <andreas@kemnade.info>
Cc: imx@lists.linux.dev, devicetree@vger.kernel.org, robh@kernel.org,
	conor+dt@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH v2 2/3] timer-imx-gpt: Allow 32K clock to be used as a clock source
Date: Thu, 26 Nov 2026 11:14:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-235351@kernel.org> (raw)
In-Reply-To: <20261126-imx6-idlestop-v2-2-c6987e7a392f@kemnade.info>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] clocksource/drivers/timer-imx-gpt: use-after-free in
  mxc_timer_init_dt() [1]
--

commit 870748ba8cec003b2bb83b77fde7449ddd3b4055
Author: Andreas Kemnade <andreas@kemnade.info>

timer-imx-gpt: Allow 32K clock to be used as a clock source

This commit configures the i.MX GPT timer control register and minimum
clockevent delta to allow using the 32.768 kHz clock as a clock source.

> diff --git a/drivers/clocksource/timer-imx-gpt.c b/drivers/clocksource/timer-imx-gpt.c
> index 8335bd7f8c6ce..85fd36fe1c760 100644
> --- a/drivers/clocksource/timer-imx-gpt.c
> +++ b/drivers/clocksource/timer-imx-gpt.c

[ ... ]

> @@ -281,8 +284,7 @@ static int __init mxc_clockevent_init(struct imx_timer *imxtm)
>  	ced->rating = 200;
>  	ced->cpumask = cpumask_of(0);
>  	ced->irq = imxtm->irq;
> -	clockevents_config_and_register(ced, clk_get_rate(imxtm->clk_per),
> -					0xff, 0xfffffffe);
> +	clockevents_config_and_register(ced, rate, rate == 32768 ? 3 : 0xff, 0xfffffffe);
>  
>  	return request_irq(imxtm->irq, mxc_timer_interrupt,
>  			   IRQF_TIMER | IRQF_IRQPOLL, "i.MX Timer Tick", ced);

[Severity: Critical]
This problem wasn't introduced by this patch, but can a failure in
request_irq() cause a use-after-free on imxtm->ced [1]?

mxc_clockevent_init() registers imxtm->ced with
clockevents_config_and_register() before calling request_irq().  If
request_irq() fails, the error propagates through _mxc_timer_init() to
mxc_timer_init_dt(), which frees imxtm while the clockevents core still
holds a reference to the registered ced:

drivers/clocksource/timer-imx-gpt.c:mxc_timer_init_dt() {
	...
	ret = _mxc_timer_init(imxtm);
	if (ret)
		goto err_kfree;
	...
err_kfree:
	kfree(imxtm);
	return ret;
}

Requesting the IRQ before calling clockevents_config_and_register() would
avoid leaving a registered clock_event_device behind on failure.

[1] https://sashiko.dev/#/bug/linux-b33465da-04a0-4dc9-8c09-6d0b6a5ad47b

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-imx6-idlestop-v2-0-c6987e7a392f@kemnade.info?part=2

  reply	other threads:[~2026-11-26 11:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 11:00 [PATCH v2 0/3] ARM: imx: Add a more agressive idle mode on i.MX6SLL Andreas Kemnade
2026-11-26 11:00 ` [PATCH v2 1/3] ARM: imx: enable STOP-ON mode in idle if wakeup requirements permit Andreas Kemnade
2026-11-26 11:13   ` sashiko-bot
2026-11-26 12:46     ` Andreas Kemnade
2026-11-26 11:00 ` [PATCH v2 2/3] timer-imx-gpt: Allow 32K clock to be used as a clock source Andreas Kemnade
2026-11-26 11:14   ` sashiko-bot [this message]
2026-11-26 11:00 ` [PATCH v2 3/3] ARM: dts: imx: kobo-clarahd: Use 32K clock for the timer Andreas Kemnade

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-235351@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=andreas@kemnade.info \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=imx@lists.linux.dev \
    --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