Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: ds1305: Report maximum alarm limit to rtc core

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>

authored by

Guenter Roeck and committed by
Alexandre Belloni
46b79ac0 3637bbdc

+3 -2
+3 -2
drivers/rtc/rtc-ds1305.c
··· 336 336 /* make sure alarm fires within the next 24 hours */ 337 337 if (later <= now) 338 338 return -EINVAL; 339 - if ((later - now) > 24 * 60 * 60) 340 - return -EDOM; 339 + if ((later - now) > ds1305->rtc->alarm_offset_max) 340 + return -ERANGE; 341 341 342 342 /* disable alarm if needed */ 343 343 if (ds1305->ctrl[0] & DS1305_AEI0) { ··· 691 691 ds1305->rtc->ops = &ds1305_ops; 692 692 ds1305->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 693 693 ds1305->rtc->range_max = RTC_TIMESTAMP_END_2099; 694 + ds1305->rtc->alarm_offset_max = 24 * 60 * 60; 694 695 695 696 ds1305_nvmem_cfg.priv = ds1305; 696 697 status = devm_rtc_register_device(ds1305->rtc);