mirror of https://lore.kernel.org/lkml/
 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 v2] iio: magnetometer: mag3110: claim direct mode during raw reads
Date: Sun, 21 Aug 2016 19:38:01 +0100	[thread overview]
Message-ID: <f69f16a6-0d51-3211-81e3-16580817572d@kernel.org> (raw)
In-Reply-To: <20160818160849.GA21203@d830.WORKGROUP>

On 18/08/16 17:09, 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 raw reads.
> 
> Signed-off-by: Alison Schofield <amsfield22@gmail.com>
> Cc: Daniel Baluta <daniel.baluta@gmail.com>
Applied to the togreg branch of iio.git. Initially pushed
out as testing for the autobuilders to play with it.

Thanks,

Jonathan
> ---
> Changes in v2:
>  added breaks in switch to prevent fall through
> 
>  drivers/iio/magnetometer/mag3110.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c
> index f2be4a0..f2b3bd7 100644
> --- a/drivers/iio/magnetometer/mag3110.c
> +++ b/drivers/iio/magnetometer/mag3110.c
> @@ -154,34 +154,41 @@ static int mag3110_read_raw(struct iio_dev *indio_dev,
>  
>  	switch (mask) {
>  	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_MAGN: /* in 0.1 uT / LSB */
>  			ret = mag3110_read(data, buffer);
>  			if (ret < 0)
> -				return ret;
> +				goto release;
>  			*val = sign_extend32(
>  				be16_to_cpu(buffer[chan->scan_index]), 15);
> -			return IIO_VAL_INT;
> +			ret = IIO_VAL_INT;
> +			break;
>  		case IIO_TEMP: /* in 1 C / LSB */
>  			mutex_lock(&data->lock);
>  			ret = mag3110_request(data);
>  			if (ret < 0) {
>  				mutex_unlock(&data->lock);
> -				return ret;
> +				goto release;
>  			}
>  			ret = i2c_smbus_read_byte_data(data->client,
>  				MAG3110_DIE_TEMP);
>  			mutex_unlock(&data->lock);
>  			if (ret < 0)
> -				return ret;
> +				goto release;
>  			*val = sign_extend32(ret, 7);
> -			return IIO_VAL_INT;
> +			ret = IIO_VAL_INT;
> +			break;
>  		default:
> -			return -EINVAL;
> +			ret = -EINVAL;
>  		}
> +release:
> +		iio_device_release_direct_mode(indio_dev);
> +		return ret;
> +
>  	case IIO_CHAN_INFO_SCALE:
>  		switch (chan->type) {
>  		case IIO_MAGN:
> 

      reply	other threads:[~2016-08-21 18:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-18 16:09 Alison Schofield
2016-08-21 18:38 ` 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=f69f16a6-0d51-3211-81e3-16580817572d@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

all inboxes | Powered by JetHome®