mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Joshua Kinard <linux@kumba.dev>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Imre Kaloz <kaloz@kernel.org>,
	Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 08/10] rtc: ds1685: check driver data for NULL in ds1685_rtc_poweroff()
Date: Mon, 23 Nov 2026 19:59:19 +0000	[thread overview]
Message-ID: <20261123200012.502284-9-lee@kernel.org> (raw)
In-Reply-To: <20261123200012.502284-1-lee@kernel.org>

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@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 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


  parent reply	other threads:[~2026-11-23 20:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
2026-11-23 19:59 ` [PATCH 01/10] rtc: rx8025: pass parent I2C device in clock_adjust_ppb sysfs callbacks Lee Jones
2026-11-23 19:59 ` [PATCH 02/10] rtc: mt6397: handle non-DT platform device matching in probe Lee Jones
2026-11-23 19:59 ` [PATCH 03/10] rtc: ma35d1: allocate RTC device before requesting interrupt Lee Jones
2026-11-23 19:59 ` [PATCH 04/10] rtc: mpc5121: get interrupts via platform_get_irq() Lee Jones
2026-11-23 19:59 ` [PATCH 05/10] rtc: m41t80: use devm helpers for square-wave clock registration Lee Jones
2026-11-23 19:59 ` [PATCH 06/10] rtc: nct3018y: fix clock provider use-after-free and leak on unbind Lee Jones
2026-11-23 19:59 ` [PATCH 07/10] rtc: stmp3xxx: unregister child watchdog platform device " Lee Jones
2026-11-23 19:59 ` Lee Jones [this message]
2026-11-23 19:59 ` [PATCH 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path Lee Jones
2026-11-23 19:59 ` [PATCH 10/10] rtc: bq32k: use u8 register buffer in trickle_charge_bypass sysfs Lee Jones

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=20261123200012.502284-9-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=kaloz@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux@kumba.dev \
    --cc=matthias.fuchs@esd-electronics.com \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®