Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37812d2e authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Jonathan Cameron
Browse files

staging:iio:trigger:bfintmr: Avoid divide by zero



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: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent a0e545e0
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -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,