Commit e5cc9840 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Jonathan Cameron

iio: buffer: Use dedicated variable in iio_buffers_alloc_sysfs_and_mask()

Use dedicated variable for index in the loop in the
iio_buffers_alloc_sysfs_and_mask(). This will make code cleaner and
less error prone as proved by previous changes done in this function.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20211013094923.2473-3-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 7d71d289
...@@ -1727,8 +1727,7 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev) ...@@ -1727,8 +1727,7 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
const struct iio_chan_spec *channels; const struct iio_chan_spec *channels;
struct iio_buffer *buffer; struct iio_buffer *buffer;
int unwind_idx; int ret, i, idx;
int ret, i;
size_t sz; size_t sz;
channels = indio_dev->channels; channels = indio_dev->channels;
...@@ -1743,15 +1742,12 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev) ...@@ -1743,15 +1742,12 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
if (!iio_dev_opaque->attached_buffers_cnt) if (!iio_dev_opaque->attached_buffers_cnt)
return 0; return 0;
for (i = 0; i < iio_dev_opaque->attached_buffers_cnt; i++) { for (idx = 0; idx < iio_dev_opaque->attached_buffers_cnt; idx++) {
buffer = iio_dev_opaque->attached_buffers[i]; buffer = iio_dev_opaque->attached_buffers[idx];
ret = __iio_buffer_alloc_sysfs_and_mask(buffer, indio_dev, i); ret = __iio_buffer_alloc_sysfs_and_mask(buffer, indio_dev, idx);
if (ret) { if (ret)
unwind_idx = i - 1;
goto error_unwind_sysfs_and_mask; goto error_unwind_sysfs_and_mask;
}
} }
unwind_idx = iio_dev_opaque->attached_buffers_cnt - 1;
sz = sizeof(*(iio_dev_opaque->buffer_ioctl_handler)); sz = sizeof(*(iio_dev_opaque->buffer_ioctl_handler));
iio_dev_opaque->buffer_ioctl_handler = kzalloc(sz, GFP_KERNEL); iio_dev_opaque->buffer_ioctl_handler = kzalloc(sz, GFP_KERNEL);
...@@ -1767,9 +1763,9 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev) ...@@ -1767,9 +1763,9 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
return 0; return 0;
error_unwind_sysfs_and_mask: error_unwind_sysfs_and_mask:
for (; unwind_idx >= 0; unwind_idx--) { while (idx--) {
buffer = iio_dev_opaque->attached_buffers[unwind_idx]; buffer = iio_dev_opaque->attached_buffers[idx];
__iio_buffer_free_sysfs_and_mask(buffer, indio_dev, unwind_idx); __iio_buffer_free_sysfs_and_mask(buffer, indio_dev, idx);
} }
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment