Commit 4c4e5df1 authored by Baolin Wang's avatar Baolin Wang Committed by Alexandre Belloni

rtc: Factor out the RTC range validation into rtc_valid_range()

The RTC range validation code can be factored into rtc_valid_range()
function to avoid duplicate code.
Signed-off-by: default avatarBaolin Wang <baolin.wang@linaro.org>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 71db049e
...@@ -23,6 +23,18 @@ ...@@ -23,6 +23,18 @@
static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer); static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer);
static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer); static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer);
static int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm)
{
if (rtc->range_min != rtc->range_max) {
time64_t time = rtc_tm_to_time64(tm);
if (time < rtc->range_min || time > rtc->range_max)
return -ERANGE;
}
return 0;
}
static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
{ {
int err; int err;
...@@ -70,12 +82,9 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) ...@@ -70,12 +82,9 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
if (err != 0) if (err != 0)
return err; return err;
if (rtc->range_min != rtc->range_max) { err = rtc_valid_range(rtc, tm);
time64_t time = rtc_tm_to_time64(tm); if (err)
return err;
if (time < rtc->range_min || time > rtc->range_max)
return -ERANGE;
}
err = mutex_lock_interruptible(&rtc->ops_lock); err = mutex_lock_interruptible(&rtc->ops_lock);
if (err) if (err)
...@@ -381,12 +390,9 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) ...@@ -381,12 +390,9 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
if (err != 0) if (err != 0)
return err; return err;
if (rtc->range_min != rtc->range_max) { err = rtc_valid_range(rtc, &alarm->time);
time64_t time = rtc_tm_to_time64(&alarm->time); if (err)
return err;
if (time < rtc->range_min || time > rtc->range_max)
return -ERANGE;
}
err = mutex_lock_interruptible(&rtc->ops_lock); err = mutex_lock_interruptible(&rtc->ops_lock);
if (err) if (err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment