rtc: ds1305: Report maximum alarm limit to rtc core
authorGuenter Roeck <linux@roeck-us.net>
Thu, 17 Aug 2023 22:55:36 +0000 (15:55 -0700)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Sun, 27 Aug 2023 21:50:22 +0000 (23:50 +0200)
DS1305 only supports alarms up to 24 hours in the future.
Report the limit to the RTC core, and use the reported limit
to validate the requested alarm time when setting it.

If the alarm is too large when trying to set an alarm, return -ERANGE
instead of -EDOM to align with error codes returned by other rtc drivers.

Cc: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20230817225537.4053865-7-linux@roeck-us.net
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-ds1305.c

index ed93604..d4de401 100644 (file)
@@ -336,8 +336,8 @@ static int ds1305_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
        /* make sure alarm fires within the next 24 hours */
        if (later <= now)
                return -EINVAL;
-       if ((later - now) > 24 * 60 * 60)
-               return -EDOM;
+       if ((later - now) > ds1305->rtc->alarm_offset_max)
+               return -ERANGE;
 
        /* disable alarm if needed */
        if (ds1305->ctrl[0] & DS1305_AEI0) {
@@ -691,6 +691,7 @@ static int ds1305_probe(struct spi_device *spi)
        ds1305->rtc->ops = &ds1305_ops;
        ds1305->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
        ds1305->rtc->range_max = RTC_TIMESTAMP_END_2099;
+       ds1305->rtc->alarm_offset_max = 24 * 60 * 60;
 
        ds1305_nvmem_cfg.priv = ds1305;
        status = devm_rtc_register_device(ds1305->rtc);