pwm: bcm2835: Prevent division by zero
authorStefan Wahren <stefan.wahren@i2se.com>
Tue, 1 Dec 2015 22:55:40 +0000 (22:55 +0000)
committerThierry Reding <thierry.reding@gmail.com>
Wed, 16 Dec 2015 15:45:10 +0000 (16:45 +0100)
It's possible that the PWM clock becomes an orphan. So better check the
result of clk_get_rate() in order to prevent a division by zero.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-bcm2835.c

index 174cca92f6906218a832f0e809586460fb5185c1..31a6992a445c038a5f82f2bc6642d334f8e65999 100644 (file)
@@ -65,7 +65,15 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
                              int duty_ns, int period_ns)
 {
        struct bcm2835_pwm *pc = to_bcm2835_pwm(chip);
-       unsigned long scaler = NSEC_PER_SEC / clk_get_rate(pc->clk);
+       unsigned long rate = clk_get_rate(pc->clk);
+       unsigned long scaler;
+
+       if (!rate) {
+               dev_err(pc->dev, "failed to get clock rate\n");
+               return -EINVAL;
+       }
+
+       scaler = NSEC_PER_SEC / rate;
 
        if (period_ns <= MIN_PERIOD) {
                dev_err(pc->dev, "period %d not supported, minimum %d\n",