Linux RTC
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Imre Kaloz" <kaloz@kernel.org>
Cc: linux-rtc@vger.kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH v2 1/3] rtc: ds1685: arm the wake-up alarm at power-off only if an alarm is set
Date: Tue, 13 Oct 2026 12:15:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-169684@kernel.org> (raw)
In-Reply-To: <20261013120208.11268-2-kaloz@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] rtc: ds1685: NULL pointer deref in poweroff handler if unbound
--

commit e81b71e9197dea1b3b5991740fdeeb891e509522
Author: Imre Kaloz <kaloz@kernel.org>

rtc: ds1685: arm the wake-up alarm at power-off only if an alarm is set

This commit modifies the DS1685 RTC driver to only arm the wake-up alarm
during power-off if an alarm is actually set. It prevents stale alarm
registers from inadvertently powering the machine back on.

> diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
> index 5fc8e36b1abf8..94c89333c5d5c 100644
> --- a/drivers/rtc/rtc-ds1685.c
> +++ b/drivers/rtc/rtc-ds1685.c
> @@ -1367,7 +1367,7 @@ module_platform_driver(ds1685_rtc_driver);
>  void __noreturn
>  ds1685_rtc_poweroff(struct platform_device *pdev)
>  {
> -	u8 ctrla, ctrl4a, ctrl4b;
> +	u8 ctrla, ctrlb, ctrl4a, ctrl4b;
>  	struct ds1685_priv *rtc;
>  
>  	/* Check for valid RTC data, else, spin forever. */

[ ... ]

> @@ -1394,6 +1394,8 @@ ds1685_rtc_poweroff(struct platform_device *pdev)
>  		ctrla &= ~(RTC_CTRL_A_DV2);
>  		rtc->write(rtc, RTC_CTRL_A, ctrla);
>  
> +		ctrlb = rtc->read(rtc, RTC_CTRL_B);

[Severity: High]
Can this lead to a NULL pointer dereference during the system poweroff
sequence?

If the driver failed to probe or was explicitly unbound via sysfs,
platform_get_drvdata(pdev) will return NULL. When the global shutdown handler
calls ds1685_rtc_poweroff(), we fetch the driver data and dereference it
without checking:

        /* Get the rtc data. */
        rtc = platform_get_drvdata(pdev);

        /* ... */
        if (rtc->irq_num)
                disable_irq_nosync(rtc->irq_num);

        ctrla = rtc->read(rtc, RTC_CTRL_A);

Could this hang the system instead of powering off by causing a panic when rtc
is NULL?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261013120208.11268-1-kaloz@kernel.org?part=1

  reply	other threads:[~2026-10-13 12:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 12:02 [PATCH v2 0/3] rtc: ds1685: power-off fixes Imre Kaloz
2026-10-13 12:02 ` [PATCH v2 1/3] rtc: ds1685: arm the wake-up alarm at power-off only if an alarm is set Imre Kaloz
2026-10-13 12:15   ` sashiko-bot [this message]
2026-10-13 12:02 ` [PATCH v2 2/3] rtc: ds1685: do not sleep in the power-off handler Imre Kaloz
2026-10-13 12:24   ` sashiko-bot
2026-10-13 12:02 ` [PATCH v2 3/3] rtc: ds1685: keep setting PAB until power is removed Imre Kaloz
2026-10-13 12:30   ` sashiko-bot

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=sashiko-outbox-169684@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=kaloz@kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --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