Hello, On Mon, May 19, 2014 at 10:29:05AM -0700, Sören Brinkmann wrote: > With the improvements suggested by you I have this now: > > long clk_round_rate_nearest(struct clk *clk, unsigned long rate) > { > unsigned long lower, upper; > > lower = clk_round_rate(clk, rate); > if (lower >= rate) > return lower; > > upper = clk_round_rate(clk, rate + (rate - lower) - 1); > if (upper == lower) > return upper; > > lower = rate + 1; > while (lower < upper) { > unsigned long rounded, mid; > > mid = lower + ((upper - lower) >> 1); > rounded = clk_round_rate(clk, mid); > if (rounded < lower) > lower = mid + 1; > else > upper = rounded; > } > > return upper; > } This is nearly my version now. I just lacks the overflow check when calculating upper and I skipped the early return if (upper == lower). (Instead the while condition evaluates to false on the first hit and returns with the same result.) Other than that I added a few comments. :-) Something we still should resolve is the return type. It should match clk_round_rate, but should both be signed or unsigned? Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ | -- To unsubscribe from this list: send the line "unsubscribe cpufreq" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html