@@ -412,6 +412,12 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
time64_t now, scheduled;
int err;
+ if (!rtc->ops)
+ err = -ENODEV;
+ else if (rtc->ops->has_alarm &&
+ !rtc->ops->has_alarm(rtc->dev.parent))
+ return -EINVAL;
+
err = rtc_valid_tm(&alarm->time);
if (err)
return err;
@@ -66,6 +66,7 @@ struct rtc_class_ops {
int (*alarm_irq_enable)(struct device *, unsigned int enabled);
int (*read_offset)(struct device *, long *offset);
int (*set_offset)(struct device *, long offset);
+ int (*has_alarm)(struct device *);
};
struct rtc_device;
The method enables determining whether a device supports setting alarms or not before checking if the alarm to be set is in the past; thus, provides clear indication of support for alarms in a given configuration. Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com> --- How about has_alarm() method. It can be checked at the beginning of __rtc_set_alarm() like RTC_HAS_ALARM flag I proposed above, but doesn't need to be introduced in all drivers at once. See the following message for the implementation in the ds1307 driver. The first uie_unsupported patch should be kept regardless of these two. drivers/rtc/interface.c | 6 ++++++ include/linux/rtc.h | 1 + 2 files changed, 7 insertions(+)