From: Jonathan Cameron <jic23@kernel.org>
To: Rohit Sarkar <rohitsarkar5398@gmail.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
dragos.bogdan@analog.com
Subject: Re: [PATCH v7] iio: adc: max1363: replace uses of mlock
Date: Sun, 22 Mar 2020 17:52:27 +0000 [thread overview]
Message-ID: <20200322175227.1623048e@archlinux> (raw)
In-Reply-To: <5e766058.1c69fb81.a65ff.d2eb@mx.google.com>
On Sun, 22 Mar 2020 00:13:32 +0530
Rohit Sarkar <rohitsarkar5398@gmail.com> wrote:
> Hey,
> Does this look fine? Wondering if this was missed during review
> Thanks,
> Rohit
Nope just a busy week. + I review from latest emails backwards
(and almost always get through everything).
Questions have a habit of being resolved quicker that way
around ;)
Jonathan
>
> On Sun, Mar 15, 2020 at 09:34:58PM +0530, Rohit Sarkar 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>
> > ---
> > Changelog v6 -> v7
> > * Fix failure handling logic
> >
> > Changelog v5 -> v6
> > * Minor failure handling fixes
> >
> > Changelog v4 -> v5
> > * Use local lock too at places where driver state needs to be protected.
> >
> > Changelog v3 -> v4
> > * Fix indentation
> >
> > Changelog v2 -> v3
> > * use iio_device_claim_direct when switching modes
> > * replace mlock usage in max1363_write_event_config
> >
> > Changelog v1 -> v2
> > * Fix indentation
> >
> > drivers/iio/adc/max1363.c | 37 ++++++++++++++++++++++++++++---------
> > 1 file changed, 28 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
> > index 5c2cc61b666e..12d72bf3f12a 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,13 @@ 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)
> > + return ret;
> > + mutex_lock(&st->lock);
> > +
> > + 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 +380,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 +412,10 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
> > data = rxbuf[0];
> > }
> > *val = data;
> > +
> > error_ret:
> > - mutex_unlock(&indio_dev->mlock);
> > + mutex_unlock(&st->lock);
> > + iio_device_release_direct_mode(indio_dev);
> > return ret;
> >
> > }
> > @@ -705,9 +715,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 +820,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 +972,14 @@ static int max1363_write_event_config(struct iio_dev *indio_dev,
> > u16 unifiedmask;
> > int number = chan->channel;
> >
> > - mutex_lock(&indio_dev->mlock);
> > + ret = iio_device_claim_direct_mode(indio_dev);
> > + if (ret)
> > + return ret;
> > + mutex_lock(&st->lock);
> > +
> > + if (ret < 0)
> > + goto error_ret;
> > +
> > unifiedmask = st->mask_low | st->mask_high;
> > if (dir == IIO_EV_DIR_FALLING) {
> >
> > @@ -989,7 +1006,8 @@ 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);
> > + mutex_unlock(&st->lock);
> > + iio_device_release_direct_mode(indio_dev);
> >
> > return ret;
> > }
> > @@ -1587,6 +1605,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
> >
next prev parent reply other threads:[~2020-03-22 17:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-15 16:04 [PATCH v7] iio: adc: max1363: replace uses of mlock Rohit Sarkar
2020-03-21 18:43 ` Rohit Sarkar
2020-03-22 17:52 ` Jonathan Cameron [this message]
2020-03-22 17:53 ` Jonathan Cameron
2020-03-30 13:39 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200322175227.1623048e@archlinux \
--to=jic23@kernel.org \
--cc=dragos.bogdan@analog.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rohitsarkar5398@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.