lkml.org 
[lkml]   [2016]   [Aug]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] rtc-cmos: Reject unsupported alarm values
From
Date
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 <gabriele.mzt@gmail.com>
> ---
> 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;
>

\
 
 \ /
  Last update: 2016-09-17 09:58    [W:2.197 / U:0.588 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site