Re: [PATCH 1/4] staging:iio:trigger:bfintmr: Avoid divide by zero

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 09/17/2012 01:26 PM, Lars-Peter Clausen wrote:
> 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.
Sounds like the sort of thing that only happens when setting board code up
so I'll treat it as an improvement in the code rather than an urgent fix.

Merged to togreg branch.
> 
> Signed-off-by: Lars-Peter Clausen <lars@xxxxxxxxxx>
> ---
>  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,
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux