diff options
author | Sami Kerola | 2016-07-26 09:54:00 +0200 |
---|---|---|
committer | Sami Kerola | 2017-02-05 00:39:38 +0100 |
commit | 4bfd519eeee1d0a8f47b33647011e36123d3ed4b (patch) | |
tree | 099529694373185416f273c01149b7414f054789 /sys-utils/hwclock-rtc.c | |
parent | hwclock: improve coding style (diff) | |
download | kernel-qcow2-util-linux-4bfd519eeee1d0a8f47b33647011e36123d3ed4b.tar.gz kernel-qcow2-util-linux-4bfd519eeee1d0a8f47b33647011e36123d3ed4b.tar.xz kernel-qcow2-util-linux-4bfd519eeee1d0a8f47b33647011e36123d3ed4b.zip |
hwclock: stream line synchronize_to_clock_tick_rtc()
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>
Diffstat (limited to 'sys-utils/hwclock-rtc.c')
-rw-r--r-- | sys-utils/hwclock-rtc.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/sys-utils/hwclock-rtc.c b/sys-utils/hwclock-rtc.c index f54e2633c..ba1882313 100644 --- a/sys-utils/hwclock-rtc.c +++ b/sys-utils/hwclock-rtc.c @@ -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; } |