[PATCH 08/10] rtc: ds1685: check driver data for NULL in ds1685_rtc_poweroff()

From: Lee Jones

Date: Mon Nov 23 2026 - 15:01:34 EST


ip32_poweroff() invokes ds1685_rtc_poweroff() with the static
ip32_rtc_device platform device. If ds1685_rtc_probe() previously
failed or the device was unbound, platform_get_drvdata() returns NULL
even though pdev is non-NULL, causing a NULL pointer dereference at
rtc->irq_num instead of entering the intended fallback spin loop.

Verify that platform_get_drvdata() is non-NULL alongside pdev before
dereferencing rtc.

Fixes: aaaf5fbf56f1 ("rtc: add driver for DS1685 family of real time clocks")
Closes: https://sashiko.dev/#/bug/linux-0a1838c9-65d2-4d1c-bc21-35a6a2582144
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/rtc/rtc-ds1685.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
index f27d6ae4f783..c577adf8414d 100644
--- a/drivers/rtc/rtc-ds1685.c
+++ b/drivers/rtc/rtc-ds1685.c
@@ -1370,14 +1370,12 @@ ds1685_rtc_poweroff(struct platform_device *pdev)
struct ds1685_priv *rtc;

/* Check for valid RTC data, else, spin forever. */
- if (unlikely(!pdev)) {
+ rtc = pdev ? platform_get_drvdata(pdev) : NULL;
+ if (unlikely(!rtc)) {
pr_emerg("platform device data not available, spinning forever ...\n");
while(1);
unreachable();
} else {
- /* Get the rtc data. */
- rtc = platform_get_drvdata(pdev);
-
/*
* Disable our IRQ. We're powering down, so we're not
* going to worry about cleaning up. Most of that should
--
2.56.1.750.gf70dc682cf-goog