aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiulio Benetti2020-01-17 13:06:40 +0100
committerLukasz Majewski2020-01-26 21:57:08 +0100
commit3391e7772933da74b488c761a2e444b9899cbd2a (patch)
tree32734249dcfd101ab95c1f6d35248fb686bcc7f5
parent90cbfa50c2b85d60f41d5e9852141058e5bad3ac (diff)
clk: imx: pllv3: fix potential 'divide by zero' in sys_get_rate()
Guard 'parent_rate==0' to prevent 'divide by zero' issue in clk_pplv3_sys_get_rate(). If it is 0, let's return with -EINVAL. Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
-rw-r--r--drivers/clk/imx/clk-pllv3.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/clk/imx/clk-pllv3.c b/drivers/clk/imx/clk-pllv3.c
index fc16416d5fb..a540a5b68c6 100644
--- a/drivers/clk/imx/clk-pllv3.c
+++ b/drivers/clk/imx/clk-pllv3.c
@@ -121,10 +121,16 @@ static ulong clk_pllv3_sys_set_rate(struct clk *clk, ulong rate)
{
struct clk_pllv3 *pll = to_clk_pllv3(clk);
unsigned long parent_rate = clk_get_parent_rate(clk);
- unsigned long min_rate = parent_rate * 54 / 2;
- unsigned long max_rate = parent_rate * 108 / 2;
+ unsigned long min_rate;
+ unsigned long max_rate;
u32 val, div;
+ if (parent_rate == 0)
+ return -EINVAL;
+
+ min_rate = parent_rate * 54 / 2;
+ max_rate = parent_rate * 108 / 2;
+
if (rate < min_rate || rate > max_rate)
return -EINVAL;