* [PATCH v3] iio: adc: max1363: replace uses of mlock
@ 2020-03-07 5:45 Rohit Sarkar
2020-03-07 13:59 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Rohit Sarkar @ 2020-03-07 5:45 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, dragos.bogdan, jonathon.cameron, alexandru.ardelean
Replace usage indio_dev's mlock with either local lock or
iio_device_claim_direct_mode.
Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
---
drivers/iio/adc/max1363.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index 5c2cc61b666e..d26f68d23250 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -150,6 +150,7 @@ struct max1363_chip_info {
* @current_mode: the scan mode of this chip
* @requestedmask: a valid requested set of channels
* @reg: supply regulator
+ * @lock lock to ensure state is consistent
* @monitor_on: whether monitor mode is enabled
* @monitor_speed: parameter corresponding to device monitor speed setting
* @mask_high: bitmask for enabled high thresholds
@@ -169,6 +170,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 +366,9 @@ 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);
+ ret = iio_device_claim_direct_mode(indio_dev);
+ if (ret < 0)
+ goto error_ret;
/*
* If monitor mode is enabled, the method for reading a single
* channel will have to be rather different and has not yet
@@ -372,7 +376,7 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
*
* Also, cannot read directly if buffered capture enabled.
*/
- if (st->monitor_on || iio_buffer_enabled(indio_dev)) {
+ if (st->monitor_on) {
ret = -EBUSY;
goto error_ret;
}
@@ -404,8 +408,9 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
data = rxbuf[0];
}
*val = data;
+
error_ret:
- mutex_unlock(&indio_dev->mlock);
+ iio_device_release_direct_mode(indio_dev);
return ret;
}
@@ -705,9 +710,9 @@ static ssize_t max1363_monitor_store_freq(struct device *dev,
if (!found)
return -EINVAL;
- mutex_lock(&indio_dev->mlock);
+ mutex_lock(&st->lock);
st->monitor_speed = i;
- mutex_unlock(&indio_dev->mlock);
+ mutex_unlock(&st->lock);
return 0;
}
@@ -810,12 +815,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->lock);
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->lock);
return val;
}
@@ -962,7 +967,7 @@ static int max1363_write_event_config(struct iio_dev *indio_dev,
u16 unifiedmask;
int number = chan->channel;
- mutex_lock(&indio_dev->mlock);
+ iio_device_claim_direct_mode(indio_dev);
unifiedmask = st->mask_low | st->mask_high;
if (dir == IIO_EV_DIR_FALLING) {
@@ -989,7 +994,7 @@ static int max1363_write_event_config(struct iio_dev *indio_dev,
max1363_monitor_mode_update(st, !!(st->mask_high | st->mask_low));
error_ret:
- mutex_unlock(&indio_dev->mlock);
+ iio_device_release_direct_mode(indio_dev);
return ret;
}
@@ -1587,6 +1592,7 @@ static int max1363_probe(struct i2c_client *client,
st = iio_priv(indio_dev);
+ mutex_init(&st->lock);
st->reg = devm_regulator_get(&client->dev, "vcc");
if (IS_ERR(st->reg)) {
ret = PTR_ERR(st->reg);
--
2.23.0.385.gbc12974a89
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v3] iio: adc: max1363: replace uses of mlock
2020-03-07 5:45 [PATCH v3] iio: adc: max1363: replace uses of mlock Rohit Sarkar
@ 2020-03-07 13:59 ` Jonathan Cameron
2020-03-07 20:49 ` Rohit Sarkar
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2020-03-07 13:59 UTC (permalink / raw)
To: Rohit Sarkar
Cc: linux-iio, dragos.bogdan, jonathon.cameron, alexandru.ardelean
On Sat, 7 Mar 2020 11:15:58 +0530
Rohit Sarkar <rohitsarkar5398@gmail.com> wrote:
> Replace usage indio_dev's mlock with either local lock or
> iio_device_claim_direct_mode.
>
> Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
If sending patches for which there is already a version on the list
which hasn't been commented on please do 2 things.
1) Reply to the previous patch email to highlight what was wrong - stops
me missing the updated version and picking up the old one.
2) change log below the ---
> ---
> drivers/iio/adc/max1363.c | 24 +++++++++++++++---------
> 1 file changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
> index 5c2cc61b666e..d26f68d23250 100644
> --- a/drivers/iio/adc/max1363.c
> +++ b/drivers/iio/adc/max1363.c
> @@ -150,6 +150,7 @@ struct max1363_chip_info {
> * @current_mode: the scan mode of this chip
> * @requestedmask: a valid requested set of channels
> * @reg: supply regulator
> + * @lock lock to ensure state is consistent
> * @monitor_on: whether monitor mode is enabled
> * @monitor_speed: parameter corresponding to device monitor speed setting
> * @mask_high: bitmask for enabled high thresholds
> @@ -169,6 +170,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 +366,9 @@ 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);
> + ret = iio_device_claim_direct_mode(indio_dev);
> + if (ret < 0)
> + goto error_ret;
> /*
> * If monitor mode is enabled, the method for reading a single
> * channel will have to be rather different and has not yet
> @@ -372,7 +376,7 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
> *
> * Also, cannot read directly if buffered capture enabled.
> */
> - if (st->monitor_on || iio_buffer_enabled(indio_dev)) {
> + if (st->monitor_on) {
> ret = -EBUSY;
> goto error_ret;
> }
> @@ -404,8 +408,9 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
> data = rxbuf[0];
> }
> *val = data;
> +
> error_ret:
> - mutex_unlock(&indio_dev->mlock);
> + iio_device_release_direct_mode(indio_dev);
> return ret;
>
> }
> @@ -705,9 +710,9 @@ static ssize_t max1363_monitor_store_freq(struct device *dev,
> if (!found)
> return -EINVAL;
>
> - mutex_lock(&indio_dev->mlock);
> + mutex_lock(&st->lock);
> st->monitor_speed = i;
> - mutex_unlock(&indio_dev->mlock);
> + mutex_unlock(&st->lock);
>
> return 0;
> }
> @@ -810,12 +815,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->lock);
> 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->lock);
>
> return val;
> }
> @@ -962,7 +967,7 @@ static int max1363_write_event_config(struct iio_dev *indio_dev,
> u16 unifiedmask;
> int number = chan->channel;
>
> - mutex_lock(&indio_dev->mlock);
> + iio_device_claim_direct_mode(indio_dev);
> unifiedmask = st->mask_low | st->mask_high;
> if (dir == IIO_EV_DIR_FALLING) {
>
> @@ -989,7 +994,7 @@ static int max1363_write_event_config(struct iio_dev *indio_dev,
>
> max1363_monitor_mode_update(st, !!(st->mask_high | st->mask_low));
> error_ret:
> - mutex_unlock(&indio_dev->mlock);
> + iio_device_release_direct_mode(indio_dev);
>
> return ret;
> }
> @@ -1587,6 +1592,7 @@ static int max1363_probe(struct i2c_client *client,
>
> st = iio_priv(indio_dev);
>
> + mutex_init(&st->lock);
> st->reg = devm_regulator_get(&client->dev, "vcc");
> if (IS_ERR(st->reg)) {
> ret = PTR_ERR(st->reg);
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v3] iio: adc: max1363: replace uses of mlock
2020-03-07 13:59 ` Jonathan Cameron
@ 2020-03-07 20:49 ` Rohit Sarkar
0 siblings, 0 replies; 3+ messages in thread
From: Rohit Sarkar @ 2020-03-07 20:49 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, dragos.bogdan, jonathon.cameron, alexandru.ardelean
On Sat, Mar 07, 2020 at 01:59:04PM +0000, Jonathan Cameron wrote:
> On Sat, 7 Mar 2020 11:15:58 +0530
> Rohit Sarkar <rohitsarkar5398@gmail.com> wrote:
>
> > Replace usage indio_dev's mlock with either local lock or
> > iio_device_claim_direct_mode.
> >
> > Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
>
> If sending patches for which there is already a version on the list
> which hasn't been commented on please do 2 things.
>
> 1) Reply to the previous patch email to highlight what was wrong - stops
> me missing the updated version and picking up the old one.
>
> 2) change log below the ---
Will keep that in mind.
Thanks,
Rohit
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-07 20:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-07 5:45 [PATCH v3] iio: adc: max1363: replace uses of mlock Rohit Sarkar
2020-03-07 13:59 ` Jonathan Cameron
2020-03-07 20:49 ` 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.