Commit e4ddf314 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Jonathan Cameron

staging:iio:adis16260: Add proper range checks to write_frequency()

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: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 2a340135
...@@ -142,29 +142,26 @@ static ssize_t adis16260_write_frequency(struct device *dev, ...@@ -142,29 +142,26 @@ static ssize_t adis16260_write_frequency(struct device *dev,
{ {
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct adis *adis = iio_priv(indio_dev); struct adis *adis = iio_priv(indio_dev);
long val; unsigned int val;
int ret; int ret;
u8 t; u8 t;
ret = strict_strtol(buf, 10, &val); ret = kstrtouint(buf, 10, &val);
if (ret) if (ret)
return ret; return ret;
if (val == 0)
return -EINVAL;
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
if (spi_get_device_id(adis->spi)->driver_data) { if (spi_get_device_id(adis->spi)->driver_data)
t = (256 / val); t = 256 / val;
if (t > 0) else
t--; t = 2048 / val;
t &= ADIS16260_SMPL_PRD_DIV_MASK;
} else { if (t > ADIS16260_SMPL_PRD_DIV_MASK)
t = (2048 / val); t = ADIS16260_SMPL_PRD_DIV_MASK;
if (t > 0) else if (t > 0)
t--; t--;
t &= ADIS16260_SMPL_PRD_DIV_MASK;
} if (t >= 0x0A)
if ((t & ADIS16260_SMPL_PRD_DIV_MASK) >= 0x0A)
adis->spi->max_speed_hz = ADIS16260_SPI_SLOW; adis->spi->max_speed_hz = ADIS16260_SPI_SLOW;
else else
adis->spi->max_speed_hz = ADIS16260_SPI_FAST; adis->spi->max_speed_hz = ADIS16260_SPI_FAST;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment