[PATCH] clk:Fix divide by 0 error in divider_ro_round_rate_parent
From: nixiaoming
Date: Fri Mar 29 2019 - 05:02:46 EST
In the function divider_recalc_rate The judgment of the return value of
_get_div indicates that the return value of _get_div may be 0.
In order to avoid the divide-by-zero error, add check the return value
of _get_div in the divider_ro_round_rate_parent
Signed-off-by: nixiaoming <nixiaoming@xxxxxxxxxx>
---
drivers/clk/clk-divider.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index e5a1726..0854e3e 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -347,6 +347,8 @@ long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
int div;
div = _get_div(table, val, flags, width);
+ if (!div) /* avoid divide-by-zero */
+ return -EINVAL;
/* Even a read-only clock can propagate a rate change */
if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) {
--
1.8.5.6