Re: [PATCH 13/15] staging:iio:adis16260: Add proper range checks to write_frequency()

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

 



On 07/17/13 15:44, Lars-Peter Clausen wrote:
> A negative sampling frequency is obviously invalid, so use kstrtouint() instead
> of strict_strtoul. Also when setting a sampling frequency smaller than the
> minimum supported frequency set the frequency to the minimum supported frequency
> instead of just cutting off the upper bits of the raw register value.
> 
> Signed-off-by: Lars-Peter Clausen <lars@xxxxxxxxxx>
Applied to the togreg branch of iio.git

Thanks
> ---
>  drivers/staging/iio/gyro/adis16260_core.c | 29 +++++++++++++----------------
>  1 file changed, 13 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c
> index b8a6a04..d4e3dd7 100644
> --- a/drivers/staging/iio/gyro/adis16260_core.c
> +++ b/drivers/staging/iio/gyro/adis16260_core.c
> @@ -142,29 +142,26 @@ static ssize_t adis16260_write_frequency(struct device *dev,
>  {
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct adis *adis = iio_priv(indio_dev);
> -	long val;
> +	unsigned int val;
>  	int ret;
>  	u8 t;
>  
> -	ret = strict_strtol(buf, 10, &val);
> +	ret = kstrtouint(buf, 10, &val);
>  	if (ret)
>  		return ret;
> -	if (val == 0)
> -		return -EINVAL;
>  
>  	mutex_lock(&indio_dev->mlock);
> -	if (spi_get_device_id(adis->spi)->driver_data) {
> -		t = (256 / val);
> -		if (t > 0)
> -			t--;
> -		t &= ADIS16260_SMPL_PRD_DIV_MASK;
> -	} else {
> -		t = (2048 / val);
> -		if (t > 0)
> -			t--;
> -		t &= ADIS16260_SMPL_PRD_DIV_MASK;
> -	}
> -	if ((t & ADIS16260_SMPL_PRD_DIV_MASK) >= 0x0A)
> +	if (spi_get_device_id(adis->spi)->driver_data)
> +		t = 256 / val;
> +	else
> +		t = 2048 / val;
> +
> +	if (t > ADIS16260_SMPL_PRD_DIV_MASK)
> +		t = ADIS16260_SMPL_PRD_DIV_MASK;
> +	else if (t > 0)
> +		t--;
> +
> +	if (t >= 0x0A)
>  		adis->spi->max_speed_hz = ADIS16260_SPI_SLOW;
>  	else
>  		adis->spi->max_speed_hz = ADIS16260_SPI_FAST;
> 
--
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