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

clk: pxa: fix pxa2xx_determine_rate return

The new pxa2xx_determine_rate() function seems lacking in a few
regards:

- For an exact match or no match at all, the rate is uninitialized
as reported by gcc -Wmaybe-unintialized:
drivers/clk/pxa/clk-pxa.c: In function 'pxa2xx_determine_rate':
drivers/clk/pxa/clk-pxa.c:243:5: error: 'rate' may be used uninitialized in this function

- If we get a non-exact match, the req->rate output is never set
to the actual rate but remains at the requested rate.

- We should not attempt to print a rate if none could be found

This rewrites the logic accordingly.

Fixes: 9fe694295098 ("clk: pxa: transfer CPU clock setting from pxa2xx-cpufreq")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

authored by

Arnd Bergmann and committed by
Stephen Boyd
2517b32b 8c1ee96a

+12 -11
+12 -11
drivers/clk/pxa/clk-pxa.c
··· 211 211 int pxa2xx_determine_rate(struct clk_rate_request *req, 212 212 struct pxa2xx_freq *freqs, int nb_freqs) 213 213 { 214 - int i, closest_below = -1, closest_above = -1, ret = 0; 214 + int i, closest_below = -1, closest_above = -1; 215 215 unsigned long rate; 216 216 217 217 for (i = 0; i < nb_freqs; i++) { ··· 230 230 231 231 req->best_parent_hw = NULL; 232 232 233 - if (i < nb_freqs) 234 - ret = 0; 235 - else if (closest_below >= 0) 233 + if (i < nb_freqs) { 234 + rate = req->rate; 235 + } else if (closest_below >= 0) { 236 236 rate = freqs[closest_below].cpll; 237 - else if (closest_above >= 0) 237 + } else if (closest_above >= 0) { 238 238 rate = freqs[closest_above].cpll; 239 - else 240 - ret = -EINVAL; 239 + } else { 240 + pr_debug("%s(rate=%lu) no match\n", __func__, req->rate); 241 + return -EINVAL; 242 + } 241 243 242 - pr_debug("%s(rate=%lu) rate=%lu: %d\n", __func__, req->rate, rate, ret); 243 - if (!rate) 244 - req->rate = rate; 244 + pr_debug("%s(rate=%lu) rate=%lu\n", __func__, req->rate, rate); 245 + req->rate = rate; 245 246 246 - return ret; 247 + return 0; 247 248 }