From 4bfd519eeee1d0a8f47b33647011e36123d3ed4b Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Tue, 26 Jul 2016 08:54:00 +0100 Subject: 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 --- sys-utils/hwclock-rtc.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'sys-utils/hwclock-rtc.c') 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; } -- cgit v1.2.3-55-g7522