public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] iio: ensure scan index is unique at device register
@ 2014-12-29  9:29 Vlad Dogaru
  2014-12-29  9:37 ` Peter Meerwald
  2014-12-29  9:38 ` Vlad Dogaru
  0 siblings, 2 replies; 3+ messages in thread
From: Vlad Dogaru @ 2014-12-29  9:29 UTC (permalink / raw)
  To: linux-iio; +Cc: Vlad Dogaru

Having two or more channels with the same positive scan_index field
makes no sense.  Prevent this situation by failing to register a device
if two scan indexes are identical.

Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
---
Changes since v3:
 - only check for duplicates if device supports buffering.
Changes since v2:
 - rebase to latest togreg branch.
Changes since v1:
 - remove redundant check for scan_index < 0 in the inner loop.

 drivers/iio/industrialio-core.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index ee442ee..dad6163 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1135,6 +1135,26 @@ static const struct file_operations iio_buffer_fileops = {
 	.compat_ioctl = iio_ioctl,
 };
 
+static int iio_check_unique_scan_index(struct iio_dev *indio_dev)
+{
+	int i, j;
+	const struct iio_chan_spec *channels = indio_dev->channels;
+
+	for (i = 0; i < indio_dev->num_channels - 1; i++) {
+		if (channels[i].scan_index < 0)
+			continue;
+		for (j = i + 1; j < indio_dev->num_channels; j++)
+			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 struct iio_buffer_setup_ops noop_ring_setup_ops;
 
 /**
@@ -1149,6 +1169,10 @@ int iio_device_register(struct iio_dev *indio_dev)
 	if (!indio_dev->dev.of_node && indio_dev->dev.parent)
 		indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
 
+	ret = iio_check_unique_scan_index(indio_dev);
+	if (ret < 0)
+		return ret;
+
 	/* configure elements for the chrdev */
 	indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] iio: ensure scan index is unique at device register
  2014-12-29  9:29 [PATCH v4] iio: ensure scan index is unique at device register Vlad Dogaru
@ 2014-12-29  9:37 ` Peter Meerwald
  2014-12-29  9:38 ` Vlad Dogaru
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Meerwald @ 2014-12-29  9:37 UTC (permalink / raw)
  To: Vlad Dogaru; +Cc: linux-iio


> Having two or more channels with the same positive scan_index field
> makes no sense.  Prevent this situation by failing to register a device
> if two scan indexes are identical.

I don't see the check whether the device supports buffering; v3 == v4 by 
mistake?

p.

> Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
> ---
> Changes since v3:
>  - only check for duplicates if device supports buffering.
> Changes since v2:
>  - rebase to latest togreg branch.
> Changes since v1:
>  - remove redundant check for scan_index < 0 in the inner loop.
> 
>  drivers/iio/industrialio-core.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index ee442ee..dad6163 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1135,6 +1135,26 @@ static const struct file_operations iio_buffer_fileops = {
>  	.compat_ioctl = iio_ioctl,
>  };
>  
> +static int iio_check_unique_scan_index(struct iio_dev *indio_dev)
> +{
> +	int i, j;
> +	const struct iio_chan_spec *channels = indio_dev->channels;
> +
> +	for (i = 0; i < indio_dev->num_channels - 1; i++) {
> +		if (channels[i].scan_index < 0)
> +			continue;
> +		for (j = i + 1; j < indio_dev->num_channels; j++)
> +			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 struct iio_buffer_setup_ops noop_ring_setup_ops;
>  
>  /**
> @@ -1149,6 +1169,10 @@ int iio_device_register(struct iio_dev *indio_dev)
>  	if (!indio_dev->dev.of_node && indio_dev->dev.parent)
>  		indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
>  
> +	ret = iio_check_unique_scan_index(indio_dev);
> +	if (ret < 0)
> +		return ret;
> +
>  	/* configure elements for the chrdev */
>  	indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
>  
> 

-- 

Peter Meerwald
+43-664-2444418 (mobile)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] iio: ensure scan index is unique at device register
  2014-12-29  9:29 [PATCH v4] iio: ensure scan index is unique at device register Vlad Dogaru
  2014-12-29  9:37 ` Peter Meerwald
@ 2014-12-29  9:38 ` Vlad Dogaru
  1 sibling, 0 replies; 3+ messages in thread
From: Vlad Dogaru @ 2014-12-29  9:38 UTC (permalink / raw)
  To: linux-iio

On Mon, Dec 29, 2014 at 11:29:21AM +0200, Vlad Dogaru wrote:
> Having two or more channels with the same positive scan_index field
> makes no sense.  Prevent this situation by failing to register a device
> if two scan indexes are identical.

Please drop this one as well, I've just sent a v5.  This just isn't my
day :)

> Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
> ---
> Changes since v3:
>  - only check for duplicates if device supports buffering.
> Changes since v2:
>  - rebase to latest togreg branch.
> Changes since v1:
>  - remove redundant check for scan_index < 0 in the inner loop.
> 
>  drivers/iio/industrialio-core.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index ee442ee..dad6163 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1135,6 +1135,26 @@ static const struct file_operations iio_buffer_fileops = {
>  	.compat_ioctl = iio_ioctl,
>  };
>  
> +static int iio_check_unique_scan_index(struct iio_dev *indio_dev)
> +{
> +	int i, j;
> +	const struct iio_chan_spec *channels = indio_dev->channels;
> +
> +	for (i = 0; i < indio_dev->num_channels - 1; i++) {
> +		if (channels[i].scan_index < 0)
> +			continue;
> +		for (j = i + 1; j < indio_dev->num_channels; j++)
> +			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 struct iio_buffer_setup_ops noop_ring_setup_ops;
>  
>  /**
> @@ -1149,6 +1169,10 @@ int iio_device_register(struct iio_dev *indio_dev)
>  	if (!indio_dev->dev.of_node && indio_dev->dev.parent)
>  		indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
>  
> +	ret = iio_check_unique_scan_index(indio_dev);
> +	if (ret < 0)
> +		return ret;
> +
>  	/* configure elements for the chrdev */
>  	indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
>  
> -- 
> 1.9.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-29  9:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-29  9:29 [PATCH v4] iio: ensure scan index is unique at device register Vlad Dogaru
2014-12-29  9:37 ` Peter Meerwald
2014-12-29  9:38 ` Vlad Dogaru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox