Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sh: clkfwk: modify for_each_frequency end condition

The end condition of for_each_frequency should care about
both clk_rate_table_round and clk_rate_div_range_round,
and using "correct max size" is a natural idea in later function.
To avoid data over flow, this patch didn't modify
clk_rate_div_range_round side as .max = div_max + 1.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>

authored by

Kuninori Morimoto and committed by
Paul Mundt
c2590f4a 56ea5109

+5 -2
+5 -2
drivers/sh/clk.c
··· 82 82 83 83 #define for_each_frequency(pos, r, freq) \ 84 84 for (pos = r->min, freq = r->func(pos, r); \ 85 - pos < r->max; pos++, freq = r->func(pos, r)) \ 85 + pos <= r->max; pos++, freq = r->func(pos, r)) \ 86 86 if (unlikely(freq == 0)) \ 87 87 ; \ 88 88 else ··· 139 139 { 140 140 struct clk_rate_round_data table_round = { 141 141 .min = 0, 142 - .max = clk->nr_freqs, 142 + .max = clk->nr_freqs - 1, 143 143 .func = clk_rate_table_iter, 144 144 .arg = freq_table, 145 145 .rate = rate, 146 146 }; 147 + 148 + if (clk->nr_freqs < 1) 149 + return 0; 147 150 148 151 return clk_rate_round_helper(&table_round); 149 152 }