]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: stream line synchronize_to_clock_tick_rtc()
authorSami Kerola <kerolasa@iki.fi>
Tue, 26 Jul 2016 07:54:00 +0000 (08:54 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sat, 4 Feb 2017 23:39:38 +0000 (23:39 +0000)
Flip if clauses to hit common case first.  This should be easier and quicker
to read and run.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/hwclock-rtc.c

index f54e2633cbef11192485c9d01c2e74a8687f3625..ba18823135fa14ec4f91884a8d383e20f47a09e3 100644 (file)
@@ -239,12 +239,12 @@ static int busywait_for_rtc_clock_tick(const struct hwclock_control *ctl,
 static int synchronize_to_clock_tick_rtc(const struct hwclock_control *ctl)
 {
        int rtc_fd;             /* File descriptor of /dev/rtc */
-       int ret;
+       int ret = 1;
 
        rtc_fd = open_rtc(ctl);
        if (rtc_fd == -1) {
                warn(_("cannot open rtc device"));
-               ret = 1;
+               return ret;
        } else {
                int rc;         /* Return code from ioctl */
                /* Turn on update interrupts (one per second) */
@@ -258,18 +258,7 @@ static int synchronize_to_clock_tick_rtc(const struct hwclock_control *ctl)
 #else
                rc = ioctl(rtc_fd, RTC_UIE_ON, 0);
 #endif
-               if (rc == -1 && (errno == ENOTTY || errno == EINVAL)) {
-                       /*
-                        * This rtc device doesn't have interrupt functions.
-                        * This is typical on an Alpha, where the Hardware
-                        * Clock interrupts are used by the kernel for the
-                        * system clock, so aren't at the user's disposal.
-                        */
-                       if (ctl->debug)
-                               printf(_("%s does not have interrupt functions. "),
-                                      rtc_dev_name);
-                       ret = busywait_for_rtc_clock_tick(ctl, rtc_fd);
-               } else if (rc == 0) {
+               if (rc != -1) {
                        /*
                         * Just reading rtc_fd fails on broken hardware: no
                         * update interrupt comes and a bootscript with a
@@ -287,26 +276,34 @@ static int synchronize_to_clock_tick_rtc(const struct hwclock_control *ctl)
                        tv.tv_sec = 10;
                        tv.tv_usec = 0;
                        rc = select(rtc_fd + 1, &rfds, NULL, NULL, &tv);
-                       ret = 1;
-                       if (rc == -1)
-                               warn(_("select() to %s to wait for clock tick failed"),
-                                    rtc_dev_name);
+                       if (0 < rc)
+                               ret = 0;
                        else if (rc == 0) {
                                if (ctl->debug)
                                        printf(_("select() to %s to wait for clock tick timed out"),
                                               rtc_dev_name);
                        } else
-                               ret = 0;
+                               warn(_("select() to %s to wait for clock tick failed"),
+                                    rtc_dev_name);
                        /* Turn off update interrupts */
                        rc = ioctl(rtc_fd, RTC_UIE_OFF, 0);
                        if (rc == -1)
                                warn(_("ioctl() to %s to turn off update interrupts failed"),
                                     rtc_dev_name);
-               } else {
+               } else if (errno == ENOTTY || errno == EINVAL) {
+                       /*
+                        * This rtc device doesn't have interrupt functions.
+                        * This is typical on an Alpha, where the Hardware
+                        * Clock interrupts are used by the kernel for the
+                        * system clock, so aren't at the user's disposal.
+                        */
+                       if (ctl->debug)
+                               printf(_("%s does not have interrupt functions. "),
+                                      rtc_dev_name);
+                       ret = busywait_for_rtc_clock_tick(ctl, rtc_fd);
+               } else
                        warn(_("ioctl() to %s to turn on update interrupts "
                              "failed unexpectedly"), rtc_dev_name);
-                       ret = 1;
-               }
        }
        return ret;
 }