lkml.org 
[lkml]   [2019]   [Oct]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 09/10] iio: gyro: adis16136: rework locks using ADIS library's state lock
On Thu, 26 Sep 2019 14:18:11 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> This replaces indio_dev's mlock with the state lock/mutex from the ADIS
> library.
>
> The __adis16136_get_freq() function has been prefixed to mark it as
> unlocked. The adis16136_{set,get}_filter() functions now hold the state
> lock for all the ops that they do.
>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Applied.

Thanks,

Jonathan

> ---
> drivers/iio/gyro/adis16136.c | 31 +++++++++++++++++++++----------
> 1 file changed, 21 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/iio/gyro/adis16136.c b/drivers/iio/gyro/adis16136.c
> index 5bec7ad53d8b..2d2c48f0b996 100644
> --- a/drivers/iio/gyro/adis16136.c
> +++ b/drivers/iio/gyro/adis16136.c
> @@ -185,12 +185,12 @@ static int adis16136_set_freq(struct adis16136 *adis16136, unsigned int freq)
> return adis_write_reg_16(&adis16136->adis, ADIS16136_REG_SMPL_PRD, t);
> }
>
> -static int adis16136_get_freq(struct adis16136 *adis16136, unsigned int *freq)
> +static int __adis16136_get_freq(struct adis16136 *adis16136, unsigned int *freq)
> {
> uint16_t t;
> int ret;
>
> - ret = adis_read_reg_16(&adis16136->adis, ADIS16136_REG_SMPL_PRD, &t);
> + ret = __adis_read_reg_16(&adis16136->adis, ADIS16136_REG_SMPL_PRD, &t);
> if (ret < 0)
> return ret;
>
> @@ -224,10 +224,13 @@ static ssize_t adis16136_read_frequency(struct device *dev,
> {
> struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> struct adis16136 *adis16136 = iio_priv(indio_dev);
> + struct mutex *slock = &adis16136->adis.state_lock;
> unsigned int freq;
> int ret;
>
> - ret = adis16136_get_freq(adis16136, &freq);
> + mutex_lock(slock);
> + ret = __adis16136_get_freq(adis16136, &freq);
> + mutex_unlock(slock);
> if (ret < 0)
> return ret;
>
> @@ -252,42 +255,50 @@ static const unsigned adis16136_3db_divisors[] = {
> static int adis16136_set_filter(struct iio_dev *indio_dev, int val)
> {
> struct adis16136 *adis16136 = iio_priv(indio_dev);
> + struct mutex *slock = &adis16136->adis.state_lock;
> unsigned int freq;
> int i, ret;
>
> - ret = adis16136_get_freq(adis16136, &freq);
> + mutex_lock(slock);
> + ret = __adis16136_get_freq(adis16136, &freq);
> if (ret < 0)
> - return ret;
> + goto out_unlock;
>
> for (i = ARRAY_SIZE(adis16136_3db_divisors) - 1; i >= 1; i--) {
> if (freq / adis16136_3db_divisors[i] >= val)
> break;
> }
>
> - return adis_write_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT, i);
> + ret = __adis_write_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT, i);
> +out_unlock:
> + mutex_unlock(slock);
> +
> + return ret;
> }
>
> static int adis16136_get_filter(struct iio_dev *indio_dev, int *val)
> {
> struct adis16136 *adis16136 = iio_priv(indio_dev);
> + struct mutex *slock = &adis16136->adis.state_lock;
> unsigned int freq;
> uint16_t val16;
> int ret;
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(slock);
>
> - ret = adis_read_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT, &val16);
> + ret = __adis_read_reg_16(&adis16136->adis, ADIS16136_REG_AVG_CNT,
> + &val16);
> if (ret < 0)
> goto err_unlock;
>
> - ret = adis16136_get_freq(adis16136, &freq);
> + ret = __adis16136_get_freq(adis16136, &freq);
> if (ret < 0)
> goto err_unlock;
>
> *val = freq / adis16136_3db_divisors[val16 & 0x07];
>
> err_unlock:
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(slock);
>
> return ret ? ret : IIO_VAL_INT;
> }

\
 
 \ /
  Last update: 2019-10-06 11:23    [W:0.200 / U:24.828 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site