]> git.baikalelectronics.ru Git - kernel.git/commitdiff
pwm: bcm-iproc: handle clk_get_rate() return
authorRayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
Sat, 18 Jul 2020 04:46:06 +0000 (21:46 -0700)
committerThierry Reding <thierry.reding@gmail.com>
Thu, 30 Jul 2020 09:27:13 +0000 (11:27 +0200)
Handle clk_get_rate() returning 0 to avoid possible division by zero.

Fixes: 84e0495bef60 ("pwm: Add support for Broadcom iProc PWM controller")
Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>
Signed-off-by: Scott Branden <scott.branden@broadcom.com>
Reviewed-by: Ray Jui <ray.jui@broadcom.com>
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-bcm-iproc.c

index 46f0a45e9049c51487cb0d5a6bb8116bc84b88b1..79b1e58e946d76702f7682c20e97fc4890ca307a 100644 (file)
@@ -85,8 +85,6 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
        u64 tmp, multi, rate;
        u32 value, prescale;
 
-       rate = clk_get_rate(ip->clk);
-
        value = readl(ip->base + IPROC_PWM_CTRL_OFFSET);
 
        if (value & BIT(IPROC_PWM_CTRL_EN_SHIFT(pwm->hwpwm)))
@@ -99,6 +97,13 @@ static void iproc_pwmc_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
        else
                state->polarity = PWM_POLARITY_INVERSED;
 
+       rate = clk_get_rate(ip->clk);
+       if (rate == 0) {
+               state->period = 0;
+               state->duty_cycle = 0;
+               return;
+       }
+
        value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET);
        prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm);
        prescale &= IPROC_PWM_PRESCALE_MAX;