imx clk: Skip reconfiguring the clock if we don't have a new best_parent

imx_clk_composite_find_best_parent can fail, when it does for all the
clocks checked we attempt to configure an uninitialized best_parent
leading to a panic.

Initialize best_parent and skip reconfiguring the clock if we don't find
a new best_parent to use.

Reviewed By: manu
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D46662
This commit is contained in:
Tom Jones 2024-09-16 15:43:31 +01:00
parent 80eb861dc2
commit 855c3dacfc

View file

@ -217,6 +217,7 @@ imx_clk_composite_set_freq(struct clknode *clk, uint64_t fparent, uint64_t *fout
p_names = clknode_get_parent_names(clk);
best_diff = 0;
best_parent = -1;
for (p_idx = 0; p_idx != clknode_get_parents_num(clk); p_idx++) {
p_clk = clknode_find_by_name(p_names[p_idx]);
@ -243,6 +244,10 @@ imx_clk_composite_set_freq(struct clknode *clk, uint64_t fparent, uint64_t *fout
if (best_diff == INT64_MAX)
return (ERANGE);
/* If we didn't find a new best_parent just return */
if (best_parent == -1)
return (0);
if ((flags & CLK_SET_DRYRUN) != 0) {
*fout = best;
return (0);