diff options
| author | Baolin Wang <baolin.wang@linaro.org> | 2018-01-08 01:04:49 -0500 |
|---|---|---|
| committer | Alexandre Belloni <alexandre.belloni@bootlin.com> | 2018-03-17 09:20:54 -0400 |
| commit | 4c4e5df1f346f70802bf4999de13d06dbbdf7a01 (patch) | |
| tree | f86ee892ed68e5abc6d845a35fff813ba4c32bf3 /drivers/rtc | |
| parent | 71db049e7355f31604e2c04b6cabb71d02bd487d (diff) | |
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>
Diffstat (limited to 'drivers/rtc')
| -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 @@ | |||
| 23 | static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer); | 23 | static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer); |
| 24 | static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer); | 24 | static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer); |
| 25 | 25 | ||
| 26 | static int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm) | ||
| 27 | { | ||
| 28 | if (rtc->range_min != rtc->range_max) { | ||
| 29 | time64_t time = rtc_tm_to_time64(tm); | ||
| 30 | |||
| 31 | if (time < rtc->range_min || time > rtc->range_max) | ||
| 32 | return -ERANGE; | ||
| 33 | } | ||
| 34 | |||
| 35 | return 0; | ||
| 36 | } | ||
| 37 | |||
| 26 | static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) | 38 | static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) |
| 27 | { | 39 | { |
| 28 | int err; | 40 | int err; |
| @@ -70,12 +82,9 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) | |||
| 70 | if (err != 0) | 82 | if (err != 0) |
| 71 | return err; | 83 | return err; |
| 72 | 84 | ||
| 73 | if (rtc->range_min != rtc->range_max) { | 85 | err = rtc_valid_range(rtc, tm); |
| 74 | time64_t time = rtc_tm_to_time64(tm); | 86 | if (err) |
| 75 | 87 | return err; | |
| 76 | if (time < rtc->range_min || time > rtc->range_max) | ||
| 77 | return -ERANGE; | ||
| 78 | } | ||
| 79 | 88 | ||
| 80 | err = mutex_lock_interruptible(&rtc->ops_lock); | 89 | err = mutex_lock_interruptible(&rtc->ops_lock); |
| 81 | if (err) | 90 | if (err) |
| @@ -381,12 +390,9 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) | |||
| 381 | if (err != 0) | 390 | if (err != 0) |
| 382 | return err; | 391 | return err; |
| 383 | 392 | ||
| 384 | if (rtc->range_min != rtc->range_max) { | 393 | err = rtc_valid_range(rtc, &alarm->time); |
| 385 | time64_t time = rtc_tm_to_time64(&alarm->time); | 394 | if (err) |
| 386 | 395 | return err; | |
| 387 | if (time < rtc->range_min || time > rtc->range_max) | ||
| 388 | return -ERANGE; | ||
| 389 | } | ||
| 390 | 396 | ||
| 391 | err = mutex_lock_interruptible(&rtc->ops_lock); | 397 | err = mutex_lock_interruptible(&rtc->ops_lock); |
| 392 | if (err) | 398 | if (err) |
