All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: linux-rtc@vger.kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCHv3] rtc: stmp3xxx: use devm_platform_ioremap_resource()
Date: Wed, 29 Jul 2026 23:00:12 +0000	[thread overview]
Message-ID: <20260729230013.562B01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260729225159.775183-1-rosenp@gmail.com>

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

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the child watchdog platform device is not unregistered when the RTC driver is unbound, leading to a resource leak, sysfs name collision, and a deterministic Use-After-Free or NULL pointer dereference.
--

--- Patch [1]: [PATCHv3] rtc: stmp3xxx: use devm_platform_ioremap_resource() ---
commit 901eb0948c2584d64b7584f8b8da4d7f0a425840
Author: Rosen Penev <rosenp@gmail.com>

rtc: stmp3xxx: use devm_platform_ioremap_resource()

This commit replaces the open-coded platform_get_resource() and
devm_ioremap() sequence with a single devm_platform_ioremap_resource() call.
It also moves the mapping ahead of devm_kzalloc() to handle errors earlier
and removes irq_alarm from the private struct.

> diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
> index 7afcd14aeee56..a8ca681b574f5 100644
> --- a/drivers/rtc/rtc-stmp3xxx.c
> +++ b/drivers/rtc/rtc-stmp3xxx.c

[ ... ]

> @@ -354,13 +350,10 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
>  	if (IS_ERR(rtc_data->rtc))
>  		return PTR_ERR(rtc_data->rtc);
>  
> -	err = devm_request_irq(&pdev->dev, rtc_data->irq_alarm,
> +	err = devm_request_irq(&pdev->dev, irq_alarm,
>  			stmp3xxx_rtc_interrupt, 0, "RTC alarm", &pdev->dev);
> -	if (err) {
> -		dev_err(&pdev->dev, "Cannot claim IRQ%d\n",
> -			rtc_data->irq_alarm);
> +	if (err)
>  		return err;
> -	}
>  
>  	rtc_data->rtc->ops = &stmp3xxx_rtc_ops;
>  	rtc_data->rtc->range_max = U32_MAX;

[Severity: High]
This is a pre-existing issue, but does the child watchdog device registered
further down in stmp3xxx_rtc_probe() outlive the RTC device if the driver
is unbound?

Looking at stmp3xxx_rtc_remove(), the child watchdog device is never
unregistered:

static void stmp3xxx_rtc_remove(struct platform_device *pdev)
{
	struct stmp3xxx_rtc_data *rtc_data = platform_get_drvdata(pdev);

	if (!rtc_data)
		return;

	writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
		rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR);
}

Since devres will free all devm_ managed resources (including rtc_data) when
the RTC driver is unbound, but the watchdog driver remains active, could
this cause a use-after-free or NULL pointer dereference?

For example, if the system shuts down after unbinding the RTC driver, the
reboot notifier in the orphaned watchdog driver could trigger:

drivers/watchdog/stmp3xxx_rtc_wdt.c:wdt_notify_sys() {
	switch (code) {
	...
	case SYS_POWER_OFF:
		wdt_stop(&stmp3xxx_wdd);
		break;
	}
}

Could this attempt to access the freed parent data when it dereferences
rtc_data->io?

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

      reply	other threads:[~2026-07-29 23:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 22:51 [PATCHv3] rtc: stmp3xxx: use devm_platform_ioremap_resource() Rosen Penev
2026-07-29 23:00 ` 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=20260729230013.562B01F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-rtc@vger.kernel.org \
    --cc=rosenp@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 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.