* [PATCH v2] clk:mmp: clk-mix.c fix divide-by-zero
@ 2019-03-30 1:27 nixiaoming
0 siblings, 0 replies; only message in thread
From: nixiaoming @ 2019-03-30 1:27 UTC (permalink / raw)
To: mturquette, sboyd, nixiaoming, chao.xie, mojha; +Cc: linux-clk, linux-kernel
The _get_div function has a branch with a return value of 0
Add a check on the return value of _get_div to avoid divide-by-zero
Signed-off-by: nixiaoming <nixiaoming@huawei.com>
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
---
drivers/clk/mmp/clk-mix.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/clk/mmp/clk-mix.c b/drivers/clk/mmp/clk-mix.c
index 90814b2..6ed5ad7 100644
--- a/drivers/clk/mmp/clk-mix.c
+++ b/drivers/clk/mmp/clk-mix.c
@@ -245,6 +245,9 @@ static int mmp_clk_mix_determine_rate(struct clk_hw *hw,
div_val_max = _get_maxdiv(mix);
for (j = 0; j < div_val_max; j++) {
div = _get_div(mix, j);
+ /* avoid divide-by-zero */
+ if (!div)
+ continue;
mix_rate = parent_rate / div;
gap = abs(mix_rate - req->rate);
if (!parent_best || gap < gap_best) {
@@ -341,6 +344,9 @@ static unsigned long mmp_clk_mix_recalc_rate(struct clk_hw *hw,
shift = mix->reg_info.shift_div;
div = _get_div(mix, MMP_CLK_BITS_GET_VAL(mux_div, width, shift));
+ /* avoid divide-by-zero */
+ if (!div)
+ return -EINVAL;
return parent_rate / div;
}
--
1.8.5.6
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-03-30 1:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-30 1:27 [PATCH v2] clk:mmp: clk-mix.c fix divide-by-zero nixiaoming
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).