diff options
author | Baolin Wang <baolin.wang@linaro.org> | 2018-01-08 09:04:49 +0300 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-03-17 16:20:54 +0300 |
commit | 4c4e5df1f346f70802bf4999de13d06dbbdf7a01 (patch) | |
tree | f86ee892ed68e5abc6d845a35fff813ba4c32bf3 | |
parent | 71db049e7355f31604e2c04b6cabb71d02bd487d (diff) | |
download | linux-4c4e5df1f346f70802bf4999de13d06dbbdf7a01.tar.xz |
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: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
-rw-r--r-- | drivers/rtc/interface.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index c068daebeec2..25aebc5b448d 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -23,6 +23,18 @@ 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 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) { int err; @@ -70,12 +82,9 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) if (err != 0) return err; - 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; - } + err = rtc_valid_range(rtc, tm); + if (err) + return err; err = mutex_lock_interruptible(&rtc->ops_lock); if (err) @@ -381,12 +390,9 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) if (err != 0) return err; - if (rtc->range_min != rtc->range_max) { - time64_t time = rtc_tm_to_time64(&alarm->time); - - if (time < rtc->range_min || time > rtc->range_max) - return -ERANGE; - } + err = rtc_valid_range(rtc, &alarm->time); + if (err) + return err; err = mutex_lock_interruptible(&rtc->ops_lock); if (err) |