lkml.org 
[lkml]   [2019]   [Oct]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 10/10] iio: imu: adis16480: use state lock for filter freq set
On Thu, 26 Sep 2019 14:18:12 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> It's the only operation that does 2 operations (a read & a write), so the
> unlocked functions can be used under a single state lock.
>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan

> ---
> drivers/iio/imu/adis16480.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
> index dc13d8a33612..01dae50e985b 100644
> --- a/drivers/iio/imu/adis16480.c
> +++ b/drivers/iio/imu/adis16480.c
> @@ -550,6 +550,7 @@ static int adis16480_set_filter_freq(struct iio_dev *indio_dev,
> const struct iio_chan_spec *chan, unsigned int freq)
> {
> struct adis16480 *st = iio_priv(indio_dev);
> + struct mutex *slock = &st->adis.state_lock;
> unsigned int enable_mask, offset, reg;
> unsigned int diff, best_diff;
> unsigned int i, best_freq;
> @@ -560,9 +561,11 @@ static int adis16480_set_filter_freq(struct iio_dev *indio_dev,
> offset = ad16480_filter_data[chan->scan_index][1];
> enable_mask = BIT(offset + 2);
>
> - ret = adis_read_reg_16(&st->adis, reg, &val);
> + mutex_lock(slock);
> +
> + ret = __adis_read_reg_16(&st->adis, reg, &val);
> if (ret < 0)
> - return ret;
> + goto out_unlock;
>
> if (freq == 0) {
> val &= ~enable_mask;
> @@ -584,7 +587,11 @@ static int adis16480_set_filter_freq(struct iio_dev *indio_dev,
> val |= enable_mask;
> }
>
> - return adis_write_reg_16(&st->adis, reg, val);
> + ret = __adis_write_reg_16(&st->adis, reg, val);
> +out_unlock:
> + mutex_unlock(slock);
> +
> + return ret;
> }
>
> static int adis16480_read_raw(struct iio_dev *indio_dev,

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