clk: Don't write error code into divider register
authorAlex Frid <afrid@nvidia.com>
Tue, 25 Jul 2017 10:18:40 +0000 (13:18 +0300)
committerStephen Boyd <sboyd@codeaurora.org>
Fri, 1 Sep 2017 01:43:38 +0000 (18:43 -0700)
Add a check for error returned by divider value calculation to avoid
writing error code into hw register.

Signed-off-by: Alex Frid <afrid@nvidia.com>
Reviewed-by: Peter De Schrijver <pdeschrijver@nvidia.com>
Reviewed-by: Jon Mayo <jmayo@nvidia.com>
Fixes: bca9690b9426 ("clk: divider: Make generic for usage elsewhere")
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
drivers/clk/clk-divider.c

index 9bb472cccca6e044e46bebc0ec57f4c74641b11b..4ed516cb72764a18a29f8cd77efcc81aa7087c47 100644 (file)
@@ -385,12 +385,14 @@ static int clk_divider_set_rate(struct clk_hw *hw, unsigned long rate,
                                unsigned long parent_rate)
 {
        struct clk_divider *divider = to_clk_divider(hw);
-       unsigned int value;
+       int value;
        unsigned long flags = 0;
        u32 val;
 
        value = divider_get_val(rate, parent_rate, divider->table,
                                divider->width, divider->flags);
+       if (value < 0)
+               return value;
 
        if (divider->lock)
                spin_lock_irqsave(divider->lock, flags);
@@ -403,7 +405,7 @@ static int clk_divider_set_rate(struct clk_hw *hw, unsigned long rate,
                val = clk_readl(divider->reg);
                val &= ~(div_mask(divider->width) << divider->shift);
        }
-       val |= value << divider->shift;
+       val |= (u32)value << divider->shift;
        clk_writel(val, divider->reg);
 
        if (divider->lock)