]> git.karo-electronics.de Git - linux-beck.git/commitdiff
iio: Always compute masklength
authorLars-Peter Clausen <lars@metafoo.de>
Fri, 29 May 2015 16:14:20 +0000 (18:14 +0200)
committerJonathan Cameron <jic23@kernel.org>
Mon, 1 Jun 2015 10:24:57 +0000 (11:24 +0100)
Even if no userspace consumer buffer is attached to the IIO device at
registration we still need to compute the masklength, since it is possible
that a in-kernel consumer buffer is going to get attached to the device at
a later point.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/industrialio-buffer.c

index dad61ab9b36fcc0413cfdd78810cd8cdfec00a7b..209c7ad793c5083ad8c0cff91f9d0ce3501851f6 100644 (file)
@@ -966,6 +966,15 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
        int ret, i, attrn, attrcount, attrcount_orig = 0;
        const struct iio_chan_spec *channels;
 
+       channels = indio_dev->channels;
+       if (channels) {
+               int ml = indio_dev->masklength;
+
+               for (i = 0; i < indio_dev->num_channels; i++)
+                       ml = max(ml, channels[i].scan_index + 1);
+               indio_dev->masklength = ml;
+       }
+
        if (!buffer)
                return 0;
 
@@ -1009,12 +1018,6 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
                        if (channels[i].scan_index < 0)
                                continue;
 
-                       /* Establish necessary mask length */
-                       if (channels[i].scan_index >
-                           (int)indio_dev->masklength - 1)
-                               indio_dev->masklength
-                                       = channels[i].scan_index + 1;
-
                        ret = iio_buffer_add_channel_sysfs(indio_dev,
                                                         &channels[i]);
                        if (ret < 0)