linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Hector Palacios <hector.palacios@digi.com>
Cc: linux-iio@vger.kernel.org, alexandre.belloni@free-electrons.com,
	jic23@kernel.org, marex@denx.de, fabio.estevam@freescale.com
Subject: Re: [PATCH 2/4] iio: mxs-lradc: add scale attribute to channels
Date: Fri, 05 Jul 2013 12:32:06 +0200	[thread overview]
Message-ID: <51D6A0A6.2020200@metafoo.de> (raw)
In-Reply-To: <1373013039-19461-3-git-send-email-hector.palacios@digi.com>

On 07/05/2013 10:30 AM, Hector Palacios wrote:
> Some LRADC channels have a fixed pre-divider, and all can have enabled
> an optional divisor by two which allows a maximum input voltage of
> VDDIO - 50mV.
> 
> This patch
>  - adds the scaling info flag to all channels
>  - adds a lookup table with max reference voltage per channel
>    (where the fixed pre-dividers apply)
>  - allows to read the scaling attribute (computed from the Vref)
> 
> Signed-off-by: Hector Palacios <hector.palacios@digi.com>

Looks good, one minor issue.

[...]
> -
> -	/* Validate the channel if it doesn't intersect with reserved chans. */
> -	bitmap_set(&mask, chan->channel, 1);
> -	ret = iio_validate_scan_mask_onehot(iio_dev, &mask);
> -	if (ret)
> -		return -EINVAL;

This will conflict with Marek's "iio: mxs-lradc: Remove useless check in
read_raw", can you apply Marek's patch to your tree and rebase this series
on-top of it?

> +
> +/*
> + * Raw I/O operations
> + */
> +static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
> +			const struct iio_chan_spec *chan,
> +			int *val, int *val2, long m)
> +{
> +	struct mxs_lradc *lradc = iio_priv(iio_dev);
> +	int ret;
> +
> +	/*
> +	 * See if there is no buffered operation in progress. If there is, simply
> +	 * bail out. This can be improved to support both buffered and raw IO at
> +	 * the same time, yet the code becomes horribly complicated. Therefore I
> +	 * applied KISS principle here.
> +	 */
> +	ret = mutex_trylock(&lradc->lock);
> +	if (!ret)
> +		return -EBUSY;

I think the locking in this driver needs some re-work (in a separate patch).
There is really no reason why you shouldn't be able to query the scale while
the device is running in buffered mode. The common idiom to protect against
concurrent buffer mode and raw access is to take the indio_dev->mlock in
read_raw, check iio_buffer_enabled(), if it returns true, unlock the lock
and return -EBUSY. Otherwise continue to read the raw value.

> +
> +	/* Check for invalid channel */
> +	if (chan->channel > LRADC_MAX_TOTAL_CHANS
> +		ret = -EINVAL;

This looks wrong. The code will still continue to read and value or the
scale and overwrite 'ret'. The original code did check this condition before
taking the lock and did return an error. But on the other hand the condition
will never be true anyway since you have no channels where the chan value is
larger than MAX_TOTAL_CHANS, so maybe just drop this completely.

> +
> +	switch(m) {
> +	case IIO_CHAN_INFO_RAW:
> +		ret = mxs_lradc_read_single(iio_dev, chan, val, val2, m);
> +		break;
> +	case IIO_CHAN_INFO_SCALE:
> +		*val = lradc->vref_mv[chan->channel];
> +		*val2 = chan->scan_type.realbits;
> +		ret = IIO_VAL_FRACTIONAL_LOG2;
> +		break;
> +	default:
> +		ret = -EINVAL;
> +		break;
> +	}
> +
>  	mutex_unlock(&lradc->lock);
>  
>  	return ret;

  reply	other threads:[~2013-07-05 10:31 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-05  8:30 [PATCH 0/4] iio: mxs-lradc: add support to optional divider_by_two Hector Palacios
2013-07-05  8:30 ` [PATCH 1/4] iio: mxs-lradc: change the realbits to 12 Hector Palacios
2013-07-05 11:37   ` Marek Vasut
2013-07-05 12:40     ` Hector Palacios
2013-07-05 13:10       ` Marek Vasut
2013-07-05 14:35         ` Hector Palacios
2013-07-05 17:17           ` Lars-Peter Clausen
2013-07-06 10:08             ` Jonathan Cameron
2013-07-06 10:13               ` Marek Vasut
2013-07-10 10:47         ` Hector Palacios
2013-07-10 11:49           ` Marek Vasut
2013-07-10 14:45             ` Hector Palacios
2013-07-10 15:22               ` Marek Vasut
2013-07-05  8:30 ` [PATCH 2/4] iio: mxs-lradc: add scale attribute to channels Hector Palacios
2013-07-05 10:32   ` Lars-Peter Clausen [this message]
2013-07-05 15:49     ` Hector Palacios
2013-07-05 16:56       ` Marek Vasut
2013-07-05 11:41   ` Marek Vasut
2013-07-05 16:42     ` Hector Palacios
2013-07-05 16:59       ` Marek Vasut
2013-07-05 17:08         ` Lars-Peter Clausen
2013-07-05 17:39           ` Marek Vasut
2013-07-06  9:59         ` Jonathan Cameron
2013-07-05  8:30 ` [PATCH 3/4] iio: mxs-lradc: add scale_available file " Hector Palacios
2013-07-05 10:40   ` Lars-Peter Clausen
2013-07-08  8:27     ` Hector Palacios
2013-07-08  8:42       ` Lars-Peter Clausen
2013-07-05 11:46   ` Marek Vasut
2013-07-08  8:51     ` Hector Palacios
2013-07-08 13:05       ` Marek Vasut
2013-07-05  8:30 ` [PATCH 4/4] iio: mxs-lradc: add write_raw function to modify scale Hector Palacios
2013-07-05 10:41   ` Lars-Peter Clausen

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=51D6A0A6.2020200@metafoo.de \
    --to=lars@metafoo.de \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=fabio.estevam@freescale.com \
    --cc=hector.palacios@digi.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=marex@denx.de \
    /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).