Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sander Speetjens" <sander.speetjens@gmail.com>
Cc: devicetree@vger.kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	conor+dt@kernel.org, robh@kernel.org, linux-rtc@vger.kernel.org
Subject: Re: [PATCH 2/3] rtc: Add Raspberry Pi 5 RTC driver
Date: Wed, 09 Sep 2026 14:34:45 +0000	[thread overview]
Message-ID: <20260909143445.78CDF1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260909141300.1368790-3-sander.speetjens@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The device tree node reference acquired via of_parse_phandle() is never released.
- [High] The firmware reference is leaked on probe errors and during driver unbind.
- [High] The driver leaks the wakeup source allocated by device_init_wakeup() on error paths and module unload.
- [Medium] The driver truncates 64-bit timestamps to 32 bits and fails to configure RTC range bounds.
--

commit 3148e2d83cccdbeec926774910d9505646955095
Author: Jonathan Bell <jonathan@raspberrypi.com>

rtc: Add Raspberry Pi 5 RTC driver

Upstreaming the downstream Raspberry Pi 5 RTC driver.
This driver supports the custom DA9091, which is accessed through the firmware
mailbox.

> diff --git a/drivers/rtc/rtc-rpi.c b/drivers/rtc/rtc-rpi.c
> new file mode 100644
> index 0000000000000..e455b4116957d
> --- /dev/null
> +++ b/drivers/rtc/rtc-rpi.c
[ ... ]
> +static int rpi_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> +	struct rpi_rtc_data *vrtc = dev_get_drvdata(dev);
> +	u32 data[2] = {RTC_TIME, rtc_tm_to_time64(tm)};

[Severity: Medium]
Does this code silently truncate the 64-bit timestamp when it assigns the 
return value of rtc_tm_to_time64() to a u32 array element?

Since rtc->range_max is left unconfigured (defaulting to 0), the RTC core 
does not enforce bounds checks. Thus, if a user attempts to set a date beyond 
year 2106, the timestamp will be truncated here, leading to silent hardware 
time corruption.

[ ... ]
> +static int rpi_rtc_probe(struct platform_device *pdev)
> +{
> +	struct rpi_rtc_data *vrtc;
> +	struct device *dev = &pdev->dev;
> +	struct device_node *np = dev->of_node;
> +	struct device_node *fw_node;
> +	struct rpi_firmware *fw;
> +	int ret;
> +
> +	fw_node = of_parse_phandle(np, "firmware", 0);
> +	if (!fw_node) {
> +		dev_err(dev, "Missing firmware node\n");
> +		return -ENOENT;
> +	}

[Severity: High]
Can this of_parse_phandle() call leak the device tree node reference? It 
acquires a reference to fw_node unconditionally, but I do not see a matching 
of_node_put(fw_node) in this function to release it once it is no longer 
needed.

> +
> +	fw = rpi_firmware_get(fw_node);
> +	if (!fw)
> +		return -EPROBE_DEFER;

[Severity: High]
Does this leak the firmware reference if the driver fails probe later, or is 
subsequently unbound? 

The rpi_firmware_get() function increments a reference count on the firmware 
object. Since there is no cleanup on error paths, nor a devm_rpi_firmware_get() 
variant used here, the resource appears to be permanently leaked when probe 
fails.

> +
> +	vrtc = devm_kzalloc(&pdev->dev, sizeof(*vrtc), GFP_KERNEL);
> +	if (!vrtc)
> +		return -ENOMEM;
> +
> +	vrtc->fw = fw;
> +
> +	device_init_wakeup(&pdev->dev, 1);

[Severity: High]
Could this leak the wakeup source allocated by device_init_wakeup() on error 
paths and during module unload? 

Because device_init_wakeup(&pdev->dev, 1) allocates a wakeup source, failing to 
call device_init_wakeup(&pdev->dev, 0) during probe failures leaves the wakeup 
source dangling.

> +
> +	platform_set_drvdata(pdev, vrtc);
> +
> +	vrtc->rtc = devm_rtc_allocate_device(&pdev->dev);
> +	if (IS_ERR(vrtc->rtc))
> +		return PTR_ERR(vrtc->rtc);
[ ... ]
> +	vrtc->rtc->ops = &rpi_rtc_ops;

[Severity: Medium]
Should rtc->range_max be properly configured before device registration? 
Without configuring the bounds, the RTC subsystem permits out-of-range times 
that will trigger the truncation issue noted earlier in rpi_rtc_set_time().

[ ... ]
> +static struct platform_driver rpi_rtc_driver = {
> +	.probe = rpi_rtc_probe,
> +	.driver = {
> +		.name = "rpi-rtc",
> +		.of_match_table = rpi_rtc_dt_match,
> +	},
> +};

[Severity: High]
Is a .remove callback missing here to handle driver unbinds? Without it, the 
firmware reference acquired by rpi_firmware_get() and the wakeup source 
allocated by device_init_wakeup() will be leaked whenever the driver is unbound 
by a local administrator.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909141300.1368790-1-sander.speetjens@gmail.com?part=2

  reply	other threads:[~2026-09-09 14:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 14:12 [PATCH 0/3] Raspberry Pi 5 RTC driver Sander Speetjens
2026-09-09 14:12 ` [PATCH 1/3] dt-bindings: rtc: Add Raspberry Pi 5 RTC binding Sander Speetjens
2026-09-09 14:23   ` sashiko-bot
2026-09-09 15:15   ` Alexandre Belloni
2026-09-09 15:47   ` Krzysztof Kozlowski
2026-09-09 15:54     ` Krzysztof Kozlowski
2026-09-09 20:38       ` Sander Speetjens
     [not found]       ` <CAAOJLPHNGgC7B=7ESCifZ1FPcR6V=Hcg-q-aaVg_9M_-d6Fh2A@mail.gmail.com>
2026-09-10  7:08         ` Krzysztof Kozlowski
2026-09-10  8:10           ` Sander Speetjens
2026-09-10 16:33           ` Stefan Wahren
2026-09-09 14:12 ` [PATCH 2/3] rtc: Add Raspberry Pi 5 RTC driver Sander Speetjens
2026-09-09 14:34   ` sashiko-bot [this message]
2026-09-09 15:20   ` Alexandre Belloni
2026-09-09 15:22   ` Alexandre Belloni
2026-09-09 15:44     ` Krzysztof Kozlowski
2026-09-09 14:13 ` [PATCH 3/3] arm64: dts: broadcom: Add RTC to Raspberry Pi 5 B Sander Speetjens
2026-09-09 14:44   ` sashiko-bot
2026-09-09 15:47   ` Krzysztof Kozlowski

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=20260909143445.78CDF1F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sander.speetjens@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