On 01/09/2016 00:59, Gabriele Mazzotta wrote: > Return an error if the user tries to set an alarm that isn't > supported by the hardware. > > Signed-off-by: Gabriele Mazzotta <[email protected]> > --- > drivers/rtc/rtc-cmos.c | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c > index 4cdb335..b3f9298 100644 > --- a/drivers/rtc/rtc-cmos.c > +++ b/drivers/rtc/rtc-cmos.c > @@ -336,6 +336,26 @@ static int cmos_set_alarm(struct device *dev, struct > rtc_wkalrm *t) > if (!is_valid_irq(cmos->irq)) > return -EIO; > > + if (!cmos->mon_alrm || !cmos->day_alrm) { > + struct rtc_time now; > + time64_t t_now; > + time64_t t_alrm; > + > + cmos_read_time(dev, &now); > + t_now = rtc_tm_to_time64(&now); > + t_alrm = rtc_tm_to_time64(&t->time); > + if (!cmos->day_alrm && (t_alrm - t_now) > (24 * 60 * 60)) { > + dev_err(dev, > + "Alarms can be up to one day in the future\n"); > + return -EINVAL; > + } > + if (!cmos->mon_alrm && (t_alrm - t_now) > (31 * 24 * 60 * 60)) {
I actually realized this is wrong. It's possible for this to let some invalid dates go through. The driver writes a date in the registers, so if mon_alrm is missing, I need to do something better than adding 31 days. Sorry, I was thinking about time deltas rather than well defined dates. > + dev_err(dev, > + "Alarms can be up to 31 days in the future\n"); > + return -EINVAL; > + } > + } > + > mon = t->time.tm_mon + 1; > mday = t->time.tm_mday; > hrs = t->time.tm_hour; > -- You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist before submitting a driver. --- You received this message because you are subscribed to the Google Groups "rtc-linux" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
