summaryrefslogtreecommitdiff
path: root/drivers/pwm
diff options
context:
space:
mode:
authorStefan Wahren <stefan.wahren@i2se.com>2015-12-02 01:55:40 +0300
committerThierry Reding <thierry.reding@gmail.com>2015-12-16 18:45:10 +0300
commitfd13c14426299e75983a0cd3edf53dfa4083a70a (patch)
tree1698122b905b9bfbaa364b11dc38ad9ac435674b /drivers/pwm
parentebe88b6ae41ff8f2b48608b6019c4341aa24bcea (diff)
downloadlinux-fd13c14426299e75983a0cd3edf53dfa4083a70a.tar.xz
pwm: bcm2835: Prevent division by zero
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>
Diffstat (limited to 'drivers/pwm')
-rw-r--r--drivers/pwm/pwm-bcm2835.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c
index 174cca92f690..31a6992a445c 100644
--- a/drivers/pwm/pwm-bcm2835.c
+++ b/drivers/pwm/pwm-bcm2835.c
@@ -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",