]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
rtc: Factor out the RTC range validation into rtc_valid_range()
authorBaolin Wang <baolin.wang@linaro.org>
Mon, 8 Jan 2018 06:04:49 +0000 (14:04 +0800)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Sat, 17 Mar 2018 13:20:54 +0000 (14:20 +0100)
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>
drivers/rtc/interface.c

index c068daebeec28f31bf3a37c1c616c4c0e9d75928..25aebc5b448d7adf8905a228a916c3f9b1894a34 100644 (file)
 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)