* [PATCH] iio: adc: max1363: replace mlock with own lock
@ 2020-02-26 18:49 Rohit Sarkar
2020-02-27 7:00 ` Ardelean, Alexandru
0 siblings, 1 reply; 3+ messages in thread
From: Rohit Sarkar @ 2020-02-26 18:49 UTC (permalink / raw)
To: linux-iio; +Cc: rohitsarkar5398, jic23, alexandru.ardelean
This change replaces indio_dev's mlock with the drivers own lock. In
each case the lock is needed to protect the driver's own state.
Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
---
drivers/iio/adc/max1363.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index 5c2cc61b666e..b9557f957f3c 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -169,6 +169,7 @@ struct max1363_state {
const struct max1363_mode *current_mode;
u32 requestedmask;
struct regulator *reg;
+ struct mutex lock;
/* Using monitor modes and buffer at the same time is
currently not supported */
@@ -364,7 +365,7 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
struct max1363_state *st = iio_priv(indio_dev);
struct i2c_client *client = st->client;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
/*
* If monitor mode is enabled, the method for reading a single
* channel will have to be rather different and has not yet
@@ -405,7 +406,7 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
}
*val = data;
error_ret:
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return ret;
}
@@ -705,9 +706,9 @@ static ssize_t max1363_monitor_store_freq(struct device *dev,
if (!found)
return -EINVAL;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->mlock);
st->monitor_speed = i;
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->mlock);
return 0;
}
@@ -810,12 +811,12 @@ static int max1363_read_event_config(struct iio_dev *indio_dev,
int val;
int number = chan->channel;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->mlock);
if (dir == IIO_EV_DIR_FALLING)
val = (1 << number) & st->mask_low;
else
val = (1 << number) & st->mask_high;
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->mlock);
return val;
}
--
2.23.0.385.gbc12974a89
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: max1363: replace mlock with own lock
2020-02-26 18:49 [PATCH] iio: adc: max1363: replace mlock with own lock Rohit Sarkar
@ 2020-02-27 7:00 ` Ardelean, Alexandru
2020-02-27 19:03 ` Rohit Sarkar
0 siblings, 1 reply; 3+ messages in thread
From: Ardelean, Alexandru @ 2020-02-27 7:00 UTC (permalink / raw)
To: rohitsarkar5398, linux-iio; +Cc: jic23
On Thu, 2020-02-27 at 00:19 +0530, Rohit Sarkar wrote:
> [External]
>
> This change replaces indio_dev's mlock with the drivers own lock. In
> each case the lock is needed to protect the driver's own state.
>
> Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
> ---
> drivers/iio/adc/max1363.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
> index 5c2cc61b666e..b9557f957f3c 100644
> --- a/drivers/iio/adc/max1363.c
> +++ b/drivers/iio/adc/max1363.c
> @@ -169,6 +169,7 @@ struct max1363_state {
> const struct max1363_mode *current_mode;
> u32 requestedmask;
> struct regulator *reg;
> + struct mutex lock;
The 'lock' field should be aligned with *reg & requestedmask.
Also, it's a good idea to do a 'mutex_init(&st->lock)' in max1363_probe().
Somewhere after 'st = iio_priv(indio_dev);'
Rest looks good
>
> /* Using monitor modes and buffer at the same time is
> currently not supported */
> @@ -364,7 +365,7 @@ static int max1363_read_single_chan(struct iio_dev
> *indio_dev,
> struct max1363_state *st = iio_priv(indio_dev);
> struct i2c_client *client = st->client;
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->lock);
> /*
> * If monitor mode is enabled, the method for reading a single
> * channel will have to be rather different and has not yet
> @@ -405,7 +406,7 @@ static int max1363_read_single_chan(struct iio_dev
> *indio_dev,
> }
> *val = data;
> error_ret:
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->lock);
> return ret;
>
> }
> @@ -705,9 +706,9 @@ static ssize_t max1363_monitor_store_freq(struct device
> *dev,
> if (!found)
> return -EINVAL;
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->mlock);
> st->monitor_speed = i;
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->mlock);
>
> return 0;
> }
> @@ -810,12 +811,12 @@ static int max1363_read_event_config(struct iio_dev
> *indio_dev,
> int val;
> int number = chan->channel;
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->mlock);
> if (dir == IIO_EV_DIR_FALLING)
> val = (1 << number) & st->mask_low;
> else
> val = (1 << number) & st->mask_high;
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->mlock);
>
> return val;
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: max1363: replace mlock with own lock
2020-02-27 7:00 ` Ardelean, Alexandru
@ 2020-02-27 19:03 ` Rohit Sarkar
0 siblings, 0 replies; 3+ messages in thread
From: Rohit Sarkar @ 2020-02-27 19:03 UTC (permalink / raw)
To: Ardelean, Alexandru; +Cc: linux-iio, jic23
On Thu, Feb 27, 2020 at 07:00:31AM +0000, Ardelean, Alexandru wrote:
> On Thu, 2020-02-27 at 00:19 +0530, Rohit Sarkar wrote:
> > [External]
> >
> > This change replaces indio_dev's mlock with the drivers own lock. In
> > each case the lock is needed to protect the driver's own state.
> >
> > Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
> > ---
> > drivers/iio/adc/max1363.c | 13 +++++++------
> > 1 file changed, 7 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
> > index 5c2cc61b666e..b9557f957f3c 100644
> > --- a/drivers/iio/adc/max1363.c
> > +++ b/drivers/iio/adc/max1363.c
> > @@ -169,6 +169,7 @@ struct max1363_state {
> > const struct max1363_mode *current_mode;
> > u32 requestedmask;
> > struct regulator *reg;
> > + struct mutex lock;
>
> The 'lock' field should be aligned with *reg & requestedmask.
Ah yes, dont know how I missed that.
> Also, it's a good idea to do a 'mutex_init(&st->lock)' in max1363_probe().
> Somewhere after 'st = iio_priv(indio_dev);'
Will do
> Rest looks good
>
Thanks,
Rohit
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-02-27 19:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 18:49 [PATCH] iio: adc: max1363: replace mlock with own lock Rohit Sarkar
2020-02-27 7:00 ` Ardelean, Alexandru
2020-02-27 19:03 ` Rohit Sarkar
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.