clk: check ->determine/round_rate() return value in clk_calc_new_rates

->determine_rate() and ->round_rate() can return the closest rate to the
requested one or an error code.
clk_calc_new_rates is assuming these functions can't return a negative
value, which leads to a undefined behavior when the clk implementation
returns such an error code.
Fix this by returning NULL in case ->determine_rate() or ->round_rate()
returned an error code.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Michael Turquette <mturquette@linaro.org>

authored by Boris Brezillon and committed by Michael Turquette 03bc10ab 45912431

Changed files
+16 -7
drivers
clk
+16 -7
drivers/clk/clk.c
··· 1618 1618 unsigned long min_rate; 1619 1619 unsigned long max_rate; 1620 1620 int p_index = 0; 1621 + long ret; 1621 1622 1622 1623 /* sanity */ 1623 1624 if (IS_ERR_OR_NULL(clk)) ··· 1634 1633 /* find the closest rate and parent clk/rate */ 1635 1634 if (clk->ops->determine_rate) { 1636 1635 parent_hw = parent ? parent->hw : NULL; 1637 - new_rate = clk->ops->determine_rate(clk->hw, rate, 1638 - min_rate, 1639 - max_rate, 1640 - &best_parent_rate, 1641 - &parent_hw); 1636 + ret = clk->ops->determine_rate(clk->hw, rate, 1637 + min_rate, 1638 + max_rate, 1639 + &best_parent_rate, 1640 + &parent_hw); 1641 + if (ret < 0) 1642 + return NULL; 1643 + 1644 + new_rate = ret; 1642 1645 parent = parent_hw ? parent_hw->core : NULL; 1643 1646 } else if (clk->ops->round_rate) { 1644 - new_rate = clk->ops->round_rate(clk->hw, rate, 1645 - &best_parent_rate); 1647 + ret = clk->ops->round_rate(clk->hw, rate, 1648 + &best_parent_rate); 1649 + if (ret < 0) 1650 + return NULL; 1651 + 1652 + new_rate = ret; 1646 1653 if (new_rate < min_rate || new_rate > max_rate) 1647 1654 return NULL; 1648 1655 } else if (!parent || !(clk->flags & CLK_SET_RATE_PARENT)) {