Commit ccd52641 authored by Nuno Sa's avatar Nuno Sa Committed by Jonathan Cameron

iio: gyro: adis16260: make use of the new lock helpers

Use the new auto cleanup based locks so error paths are simpler.

While at it, turned a sprintf() call into sysfs_emit().
Signed-off-by: default avatarNuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20240618-dev-iio-adis-cleanup-v1-4-bd93ce7845c7@analog.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent e6cab1ad
...@@ -221,13 +221,12 @@ static ssize_t adis16136_read_frequency(struct device *dev, ...@@ -221,13 +221,12 @@ static ssize_t adis16136_read_frequency(struct device *dev,
unsigned int freq; unsigned int freq;
int ret; int ret;
adis_dev_lock(&adis16136->adis); adis_dev_auto_lock(&adis16136->adis);
ret = __adis16136_get_freq(adis16136, &freq); ret = __adis16136_get_freq(adis16136, &freq);
adis_dev_unlock(&adis16136->adis);
if (ret) if (ret)
return ret; return ret;
return sprintf(buf, "%d\n", freq); return sysfs_emit(buf, "%d\n", freq);
} }
static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
...@@ -251,21 +250,17 @@ static int adis16136_set_filter(struct iio_dev *indio_dev, int val) ...@@ -251,21 +250,17 @@ static int adis16136_set_filter(struct iio_dev *indio_dev, int val)
unsigned int freq; unsigned int freq;
int i, ret; int i, ret;
adis_dev_lock(&adis16136->adis); adis_dev_auto_lock(&adis16136->adis);
ret = __adis16136_get_freq(adis16136, &freq); ret = __adis16136_get_freq(adis16136, &freq);
if (ret) if (ret)
goto out_unlock; return ret;
for (i = ARRAY_SIZE(adis16136_3db_divisors) - 1; i >= 1; i--) { for (i = ARRAY_SIZE(adis16136_3db_divisors) - 1; i >= 1; i--) {
if (freq / adis16136_3db_divisors[i] >= val) if (freq / adis16136_3db_divisors[i] >= val)
break; break;
} }
ret = __adis_write_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT, i); return __adis_write_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT, i);
out_unlock:
adis_dev_unlock(&adis16136->adis);
return ret;
} }
static int adis16136_get_filter(struct iio_dev *indio_dev, int *val) static int adis16136_get_filter(struct iio_dev *indio_dev, int *val)
...@@ -275,23 +270,20 @@ static int adis16136_get_filter(struct iio_dev *indio_dev, int *val) ...@@ -275,23 +270,20 @@ static int adis16136_get_filter(struct iio_dev *indio_dev, int *val)
uint16_t val16; uint16_t val16;
int ret; int ret;
adis_dev_lock(&adis16136->adis); adis_dev_auto_lock(&adis16136->adis);
ret = __adis_read_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT, ret = __adis_read_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT,
&val16); &val16);
if (ret) if (ret)
goto err_unlock; return ret;
ret = __adis16136_get_freq(adis16136, &freq); ret = __adis16136_get_freq(adis16136, &freq);
if (ret) if (ret)
goto err_unlock; return ret;
*val = freq / adis16136_3db_divisors[val16 & 0x07]; *val = freq / adis16136_3db_divisors[val16 & 0x07];
err_unlock: return IIO_VAL_INT;
adis_dev_unlock(&adis16136->adis);
return ret ? ret : IIO_VAL_INT;
} }
static int adis16136_read_raw(struct iio_dev *indio_dev, static int adis16136_read_raw(struct iio_dev *indio_dev,
......
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