* [PATCH v2] iio: ensure scan index is unique at buffer register
@ 2014-12-12 14:26 Vlad Dogaru
2014-12-18 16:31 ` Lars-Peter Clausen
0 siblings, 1 reply; 3+ messages in thread
From: Vlad Dogaru @ 2014-12-12 14:26 UTC (permalink / raw)
To: linux-iio, jic23, knaack.h; +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 buffer
if two scan indexes are identical.
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
---
Changes since v1:
- remove redundant check for scan_index < 0 in the inner loop.
drivers/iio/industrialio-buffer.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index f971f79..baf09c1 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -309,6 +309,27 @@ 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[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 +341,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;
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] iio: ensure scan index is unique at buffer register
2014-12-12 14:26 [PATCH v2] iio: ensure scan index is unique at buffer register Vlad Dogaru
@ 2014-12-18 16:31 ` Lars-Peter Clausen
2014-12-26 21:54 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Lars-Peter Clausen @ 2014-12-18 16:31 UTC (permalink / raw)
To: Vlad Dogaru, linux-iio, jic23, knaack.h
On 12/12/2014 03:26 PM, 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 buffer
> if two scan indexes are identical.
>
> Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
Looks ok, although I'm not convinced that we really need it.
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
[...]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] iio: ensure scan index is unique at buffer register
2014-12-18 16:31 ` Lars-Peter Clausen
@ 2014-12-26 21:54 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2014-12-26 21:54 UTC (permalink / raw)
To: Lars-Peter Clausen, Vlad Dogaru, linux-iio, knaack.h
On 18/12/14 16:31, Lars-Peter Clausen wrote:
> On 12/12/2014 03:26 PM, 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 buffer
>> if two scan indexes are identical.
>>
>> Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
>
> Looks ok, although I'm not convinced that we really need it.
>
> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
>
> [...]
I'm kind of mildly in favour of things that make bugs
less likely. However, I think this fell foul of Lars'
recent set of cleanups for the buffered code.
Could you rebase on my togreg branch.
https://git.kernel.org/cgit/linux/kernel/git/jic23/iio.git/log/?h=togreg
Thanks
Jonathan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-12-26 21:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-12 14:26 [PATCH v2] iio: ensure scan index is unique at buffer register Vlad Dogaru
2014-12-18 16:31 ` Lars-Peter Clausen
2014-12-26 21:54 ` Jonathan Cameron
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).