From: sashiko-bot@kernel.org
To: mimo-4@ilands.app, linux-rtc@vger.kernel.org
Cc: "Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH] rtc: test: cancel the alarm timer on remove
Date: Thu, 05 Nov 2026 11:01:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-198902@kernel.org> (raw)
In-Reply-To: <010101a1ab5812b4-c8329a38-bb41-40db-99e9-b4661c9c7c66-000000@us-west-2.amazonses.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] rtc: test: timer_delete_sync() in test_remove() races with alarm re-arming
--
commit 4195cfecb06de73a63ad94418a4fd408e93e1c16
Author: mimo-4@ilands.app <mimo-4@ilands.app>
rtc: test: cancel the alarm timer on remove
This commit adds a platform driver remove callback to cancel the emulated
alarm timer when the rtc-test device is removed.
> diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
> index 94f995febe5b4..1095fa2de4fb1 100644
> --- a/drivers/rtc/rtc-test.c
> +++ b/drivers/rtc/rtc-test.c
> @@ -141,8 +141,16 @@ static int test_probe(struct platform_device *plat_dev)
> return devm_rtc_register_device(rtd->rtc);
> }
>
> +static void test_remove(struct platform_device *plat_dev)
> +{
> + struct rtc_test_data *rtd = platform_get_drvdata(plat_dev);
> +
> + timer_delete_sync(&rtd->alarm);
> +}
[Severity: High]
Can rtd->alarm be re-armed after timer_delete_sync() returns in
test_remove()?
In test_probe(), the RTC device is registered via
devm_rtc_register_device(rtd->rtc), which queues devm_rtc_unregister_device()
as a devres action. During driver detach, device_remove() runs test_remove()
before device_unbind_cleanup() runs devres_release_all():
__device_release_driver()
device_remove()
test_remove()
timer_delete_sync(&rtd->alarm);
device_unbind_cleanup()
devres_release_all()
devm_rtc_unregister_device()
When test_remove() calls timer_delete_sync(&rtd->alarm),
devm_rtc_unregister_device() has not yet cleared rtd->rtc->ops or removed the
character device and sysfs attributes:
drivers/rtc/class.c:devm_rtc_unregister_device() {
mutex_lock(&rtc->ops_lock);
rtc_proc_del_device(rtc);
if (!test_bit(RTC_NO_CDEV, &rtc->flags))
cdev_device_del(&rtc->char_dev, &rtc->dev);
rtc->ops = NULL;
mutex_unlock(&rtc->ops_lock);
}
In addition, if test_rtc_alarm_handler() fired just before
timer_delete_sync(), rtc_update_irq() schedules rtd->rtc->irqwork
(rtc_timer_do_work()), which can still be pending or running and call
__rtc_set_alarm() -> test_rtc_set_alarm():
drivers/rtc/rtc-test.c:test_rtc_set_alarm() {
...
if (alrm->enabled)
add_timer(&rtd->alarm);
...
}
Because timer_delete_sync() does not prevent the timer from being re-armed, a
concurrent ioctl on /dev/rtcN, a write to sysfs wakealarm, or
rtc_timer_do_work() reprogramming an alarm before devm_rtc_unregister_device()
runs can call test_rtc_set_alarm() or test_rtc_alarm_irq_enable() and re-queue
rtd->alarm just before devres frees rtd.
Would registering the timer cleanup via devm_add_action_or_reset() before
devm_rtc_register_device(rtd->rtc), or using timer_shutdown_sync(), avoid
this race?
--
Sashiko AI review · https://sashiko.dev/#/patchset/010101a1ab5812b4-c8329a38-bb41-40db-99e9-b4661c9c7c66-000000@us-west-2.amazonses.com?part=1
prev parent reply other threads:[~2026-11-05 11:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 10:53 [PATCH] rtc: test: cancel the alarm timer on remove mimo-4
2026-11-05 11:01 ` 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=sashiko-outbox-198902@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-rtc@vger.kernel.org \
--cc=mimo-4@ilands.app \
--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