linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hartmut Knaack <knaack.h@gmx.de>
To: Vlad Dogaru <vlad.dogaru@intel.com>, linux-iio@vger.kernel.org
Subject: Re: [PATCH 2/4] iio: ensure scan index is unique at buffer register
Date: Sat, 06 Dec 2014 21:19:14 +0100	[thread overview]
Message-ID: <548364C2.10401@gmx.de> (raw)
In-Reply-To: <1416919687-14271-3-git-send-email-vlad.dogaru@intel.com>

Vlad Dogaru wrote on 25.11.2014 13:48:
> Having two or more channels with the same positive scan_index field
> makes no sense.  Prevent this situation by failing to register a buffer
> if two scan indexes are identical.
> 
> Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
> ---
>  drivers/iio/industrialio-buffer.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index f971f79..422b29e 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -309,6 +309,30 @@ static int iio_buffer_add_channel_sysfs(struct iio_dev *indio_dev,
>  	return ret;
>  }
>  
> +static int iio_check_unique_scan_index(struct iio_dev *indio_dev,
> +				       const struct iio_chan_spec *channels,
> +				       int num_channels)
> +{
> +	int i, j;
> +
> +	for (i = 0; i < num_channels - 1; i++) {
> +		if (channels[i].scan_index < 0)
> +			continue;
> +		for (j = i + 1; j < num_channels; j++) {
> +			if (channels[j].scan_index < 0)
> +				continue;
This check up here is unnecessary, since channels[i].scan_index is already equal or
greater zero, so the check below results in a false for channels[j].scan_index smaller
than zero and cause a new loop iteration anyway.

> +			if (channels[i].scan_index == channels[j].scan_index) {
> +				dev_err(&indio_dev->dev,
> +					"duplicate scan index %d\n",
> +					channels[i].scan_index);
> +				return -EINVAL;
> +			}
> +		}
> +	}
> +
> +	return 0;
> +}
> +
>  static const char * const iio_scan_elements_group_name = "scan_elements";
>  
>  int iio_buffer_register(struct iio_dev *indio_dev,
> @@ -320,6 +344,10 @@ int iio_buffer_register(struct iio_dev *indio_dev,
>  	struct iio_buffer *buffer = indio_dev->buffer;
>  	int ret, i, attrn, attrcount, attrcount_orig = 0;
>  
> +	ret = iio_check_unique_scan_index(indio_dev, channels, num_channels);
> +	if (ret < 0)
> +		return ret;
> +
>  	if (buffer->attrs)
>  		indio_dev->groups[indio_dev->groupcounter++] = buffer->attrs;
>  
> 


  reply	other threads:[~2014-12-06 20:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-25 12:48 [PATCH 0/4] Add valid sample channel Vlad Dogaru
2014-11-25 12:48 ` [PATCH 1/4] iio: dummy: set scan_index for unbuffered channels Vlad Dogaru
2014-11-25 16:11   ` Daniel Baluta
2014-12-12 11:48     ` Jonathan Cameron
2014-11-25 12:48 ` [PATCH 2/4] iio: ensure scan index is unique at buffer register Vlad Dogaru
2014-12-06 20:19   ` Hartmut Knaack [this message]
2014-12-12 11:50     ` Jonathan Cameron
2014-11-25 12:48 ` [RFC PATCH 3/4] iio: add valid sample channel Vlad Dogaru
2014-11-25 12:48 ` [RFC PATCH 4/4] iio: illustrate the use of a " Vlad Dogaru
2014-11-25 16:36 ` [PATCH 0/4] Add " Lars-Peter Clausen
2014-11-25 16:55   ` Daniel Baluta
2014-11-25 17:00     ` Lars-Peter Clausen
2014-11-25 17:29       ` Jonathan Cameron
2014-11-25 18:27         ` Octavian Purdila
2014-11-25 18:53           ` Lars-Peter Clausen
2014-11-26 12:58         ` Daniel Baluta
2014-12-01 20:06           ` Lars-Peter Clausen
2014-12-01 20:46             ` Daniel Baluta
2014-12-01 20:51               ` Lars-Peter Clausen
2014-12-01 21:03                 ` Daniel Baluta

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=548364C2.10401@gmx.de \
    --to=knaack.h@gmx.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=vlad.dogaru@intel.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 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).