staging:iio:trigger:bfintmr: Avoid divide by zero
authorLars-Peter Clausen <lars@metafoo.de>
Mon, 17 Sep 2012 12:26:00 +0000 (13:26 +0100)
committerJonathan Cameron <jic23@kernel.org>
Mon, 17 Sep 2012 21:09:59 +0000 (22:09 +0100)
If the timer frequency has not been configured yet get_gptimer_period() will
return 0. Handle this case instead of blindly dividing by the returned value.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/staging/iio/trigger/iio-trig-bfin-timer.c

index ce6a7b1b886060b6702705e7663baa9c943865ae..2772ea2fb0dc54a5d33f4bce6972fbc5f331860c 100644 (file)
@@ -99,9 +99,15 @@ static ssize_t iio_bfin_tmr_frequency_show(struct device *dev,
 {
        struct iio_trigger *trig = to_iio_trigger(dev);
        struct bfin_tmr_state *st = trig->private_data;
+       unsigned int period = get_gptimer_period(st->t->id);
+       unsigned long val;
 
-       return sprintf(buf, "%lu\n",
-                       get_sclk() / get_gptimer_period(st->t->id));
+       if (period == 0)
+               val = 0;
+       else
+               val = get_sclk() / get_gptimer_period(st->t->id);
+
+       return sprintf(buf, "%lu\n", val);
 }
 
 static DEVICE_ATTR(frequency, S_IRUGO | S_IWUSR, iio_bfin_tmr_frequency_show,