in clk/core.c [91:123]
static long clk_rate_round_helper(struct clk_rate_round_data *rounder)
{
unsigned long rate_error, rate_error_prev = ~0UL;
unsigned long highest, lowest, freq;
long rate_best_fit = -ENOENT;
int i;
highest = 0;
lowest = ~0UL;
for_each_frequency(i, rounder, freq) {
if (freq > highest)
highest = freq;
if (freq < lowest)
lowest = freq;
rate_error = abs(freq - rounder->rate);
if (rate_error < rate_error_prev) {
rate_best_fit = freq;
rate_error_prev = rate_error;
}
if (rate_error == 0)
break;
}
if (rounder->rate >= highest)
rate_best_fit = highest;
if (rounder->rate <= lowest)
rate_best_fit = lowest;
return rate_best_fit;
}