linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] staging:iio:trigger:bfintmr: Avoid divide by zero
@ 2012-09-17 12:26 Lars-Peter Clausen
  2012-09-17 12:26 ` [PATCH 2/4] staging:iio:trigger:bfintmr: Only enable timer when necessary Lars-Peter Clausen
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Lars-Peter Clausen @ 2012-09-17 12:26 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

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>
---
 drivers/staging/iio/trigger/iio-trig-bfin-timer.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
index ce6a7b1..2772ea2 100644
--- a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
+++ b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
@@ -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,
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-09-18  7:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-17 12:26 [PATCH 1/4] staging:iio:trigger:bfintmr: Avoid divide by zero Lars-Peter Clausen
2012-09-17 12:26 ` [PATCH 2/4] staging:iio:trigger:bfintmr: Only enable timer when necessary Lars-Peter Clausen
2012-09-17 21:11   ` Jonathan Cameron
2012-09-17 12:26 ` [PATCH 3/4] staging:iio:trigger:bfintmr Add output support Lars-Peter Clausen
2012-09-17 21:09   ` Jonathan Cameron
2012-09-17 12:26 ` [PATCH 4/4] iio: ad7476: Add support for the ad7091r Lars-Peter Clausen
2012-09-17 21:14   ` Jonathan Cameron
2012-09-18  7:58     ` Lars-Peter Clausen
2012-09-17 21:11 ` [PATCH 1/4] staging:iio:trigger:bfintmr: Avoid divide by zero Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).