iio: iio_buffer_register: Use correct channel when calculating masklength
[firefly-linux-kernel-4.4.55.git] / drivers / iio / industrialio-buffer.c
index ac185b8694bd7b1be5066df05921e34f201b1ba6..096a6bfe0cdfadf5d49873c6464c86199ee477d3 100644 (file)
@@ -285,11 +285,14 @@ int iio_buffer_register(struct iio_dev *indio_dev,
        if (channels) {
                /* new magic */
                for (i = 0; i < num_channels; i++) {
+                       if (channels[i].scan_index < 0)
+                               continue;
+
                        /* Establish necessary mask length */
                        if (channels[i].scan_index >
                            (int)indio_dev->masklength - 1)
                                indio_dev->masklength
-                                       = indio_dev->channels[i].scan_index + 1;
+                                       = channels[i].scan_index + 1;
 
                        ret = iio_buffer_add_channel_sysfs(indio_dev,
                                                         &channels[i]);
@@ -553,6 +556,10 @@ int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
                                            buffer->scan_mask);
        else
                indio_dev->active_scan_mask = buffer->scan_mask;
+
+       if (indio_dev->active_scan_mask == NULL)
+               return -EINVAL;
+
        iio_update_demux(indio_dev);
 
        if (indio_dev->info->update_scan_mode)