Re: [PATCHv3] rtc: stmp3xxx: use devm_platform_ioremap_resource()

[email protected] Wed, 29 Jul 2026 23:00:12 +0000
Newsgroups org.kernel.vger.linux-rtc
Message-ID <[email protected]>
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 watchd=
og platform device is not unregistered when the RTC driver is unbound, lead=
ing 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 <[email protected]>

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_devic=
e *pdev)
>  	if (IS_ERR(rtc_data->rtc))
>  		return PTR_ERR(rtc_data->rtc);
> =20
> -	err =3D devm_request_irq(&pdev->dev, rtc_data->irq_alarm,
> +	err =3D 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;
> -	}
> =20
>  	rtc_data->rtc->ops =3D &stmp3xxx_rtc_ops;
>  	rtc_data->rtc->range_max =3D 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 =3D 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?

--=20
Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20260729225159.7751=
[email protected]?part=3D1