From: Miroslav Lichvar Date: Fri, 10 Apr 2015 08:21:26 +0000 (+0200) Subject: sys: clamp frequency set in generic driver on exit X-Git-Tag: 2.0~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad942e352d91ff1b4367fe5c5caa4f0c5ceaa1ca;p=thirdparty%2Fchrony.git sys: clamp frequency set in generic driver on exit --- diff --git a/sys_generic.c b/sys_generic.c index 41e36fff..db343e55 100644 --- a/sys_generic.c +++ b/sys_generic.c @@ -107,6 +107,18 @@ handle_step(struct timeval *raw, struct timeval *cooked, double dfreq, } } +/* ================================================== */ + +static double +clamp_freq(double freq) +{ + if (freq > max_freq) + return max_freq; + if (freq < -max_freq) + return -max_freq; + return freq; +} + /* ================================================== */ /* End currently running slew and start a new one */ @@ -144,11 +156,7 @@ update_slew(void) corr_freq = max_corr_freq; /* Get the new real frequency and clamp it */ - total_freq = base_freq + corr_freq * (1.0e6 - base_freq); - if (total_freq > max_freq) - total_freq = max_freq; - else if (total_freq < -max_freq) - total_freq = -max_freq; + total_freq = clamp_freq(base_freq + corr_freq * (1.0e6 - base_freq)); /* Set the new frequency (the actual frequency returned by the call may be slightly different from the requested frequency due to rounding) */ @@ -330,7 +338,7 @@ SYS_Generic_Finalise(void) slew_timer_running = 0; } - (*drv_set_freq)(base_freq); + (*drv_set_freq)(clamp_freq(base_freq)); } /* ================================================== */