linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Alison Schofield <amsfield22@gmail.com>
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: light: ltr501: claim direct mode during select raw reads
Date: Sat, 15 Oct 2016 16:10:03 +0100	[thread overview]
Message-ID: <a743ec96-28d6-64dd-bec8-369624728d3f@kernel.org> (raw)
In-Reply-To: <20161011195620.GA9539@d830.WORKGROUP>

On 11/10/16 20:56, Alison Schofield wrote:
> Driver was checking for direct mode but not locking it.  Use
> claim/release helper functions to guarantee the device stays
> in direct mode during required raw read cases.
> 
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
The uneven levels of the claim and release in the second case
are nasty, please rework so that doesn't occur.

It will work as it is, but I'm feeling fussy ;)

Jonathan
> ---
>  drivers/iio/light/ltr501.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
> index 3afc53a..c2ac3cd 100644
> --- a/drivers/iio/light/ltr501.c
> +++ b/drivers/iio/light/ltr501.c
> @@ -631,14 +631,16 @@ static int ltr501_read_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_PROCESSED:
> -		if (iio_buffer_enabled(indio_dev))
> -			return -EBUSY;
> -
>  		switch (chan->type) {
>  		case IIO_LIGHT:
> +			ret = iio_device_claim_direct_mode(indio_dev);
> +			if (ret)
> +				return ret;
> +
>  			mutex_lock(&data->lock_als);
>  			ret = ltr501_read_als(data, buf);
>  			mutex_unlock(&data->lock_als);
> +			iio_device_release_direct_mode(indio_dev);
>  			if (ret < 0)
>  				return ret;
>  			*val = ltr501_calculate_lux(le16_to_cpu(buf[1]),
> @@ -648,14 +650,16 @@ static int ltr501_read_raw(struct iio_dev *indio_dev,
>  			return -EINVAL;
>  		}
>  	case IIO_CHAN_INFO_RAW:
> -		if (iio_buffer_enabled(indio_dev))
> -			return -EBUSY;
> +		ret = iio_device_claim_direct_mode(indio_dev);
> +		if (ret)
> +			return ret;
>  
>  		switch (chan->type) {
>  		case IIO_INTENSITY:
>  			mutex_lock(&data->lock_als);
>  			ret = ltr501_read_als(data, buf);
>  			mutex_unlock(&data->lock_als);
> +			iio_device_release_direct_mode(indio_dev);
I don't like the releasing something in the case statement which was
taken outside of it.  Either bring the claim inside as you did
above, or rework this to do the release after the switch
for all paths.
>  			if (ret < 0)
>  				return ret;
>  			*val = le16_to_cpu(chan->address == LTR501_ALS_DATA1 ?
> @@ -665,11 +669,13 @@ static int ltr501_read_raw(struct iio_dev *indio_dev,
>  			mutex_lock(&data->lock_ps);
>  			ret = ltr501_read_ps(data);
>  			mutex_unlock(&data->lock_ps);
> +			iio_device_release_direct_mode(indio_dev);
>  			if (ret < 0)
>  				return ret;
>  			*val = ret & LTR501_PS_DATA_MASK;
>  			return IIO_VAL_INT;
>  		default:
> +			iio_device_release_direct_mode(indio_dev);
>  			return -EINVAL;
>  		}
>  	case IIO_CHAN_INFO_SCALE:
> 


      reply	other threads:[~2016-10-15 15:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-11 19:56 [PATCH] iio: light: ltr501: claim direct mode during select raw reads Alison Schofield
2016-10-15 15:10 ` Jonathan Cameron [this message]

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=a743ec96-28d6-64dd-bec8-369624728d3f@kernel.org \
    --to=jic23@kernel.org \
    --cc=amsfield22@gmail.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).