Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: fix opencoded for_each_set_bit()

iio_simple_dummy_trigger_h() is mostly an opencoded for_each_set_bit().
Using for_each_set_bit() make code much cleaner, and more effective.

Signed-off-by: Yury Norov <yury.norov@gmail.com>

+19 -29
+19 -29
drivers/iio/dummy/iio_simple_dummy_buffer.c
··· 45 45 { 46 46 struct iio_poll_func *pf = p; 47 47 struct iio_dev *indio_dev = pf->indio_dev; 48 + int i = 0, j; 48 49 u16 *data; 49 50 50 51 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); 51 52 if (!data) 52 53 goto done; 53 54 54 - if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) { 55 - /* 56 - * Three common options here: 57 - * hardware scans: certain combinations of channels make 58 - * up a fast read. The capture will consist of all of them. 59 - * Hence we just call the grab data function and fill the 60 - * buffer without processing. 61 - * software scans: can be considered to be random access 62 - * so efficient reading is just a case of minimal bus 63 - * transactions. 64 - * software culled hardware scans: 65 - * occasionally a driver may process the nearest hardware 66 - * scan to avoid storing elements that are not desired. This 67 - * is the fiddliest option by far. 68 - * Here let's pretend we have random access. And the values are 69 - * in the constant table fakedata. 70 - */ 71 - int i, j; 72 - 73 - for (i = 0, j = 0; 74 - i < bitmap_weight(indio_dev->active_scan_mask, 75 - indio_dev->masklength); 76 - i++, j++) { 77 - j = find_next_bit(indio_dev->active_scan_mask, 78 - indio_dev->masklength, j); 79 - /* random access read from the 'device' */ 80 - data[i] = fakedata[j]; 81 - } 82 - } 55 + /* 56 + * Three common options here: 57 + * hardware scans: 58 + * certain combinations of channels make up a fast read. The capture 59 + * will consist of all of them. Hence we just call the grab data 60 + * function and fill the buffer without processing. 61 + * software scans: 62 + * can be considered to be random access so efficient reading is just 63 + * a case of minimal bus transactions. 64 + * software culled hardware scans: 65 + * occasionally a driver may process the nearest hardware scan to avoid 66 + * storing elements that are not desired. This is the fiddliest option 67 + * by far. 68 + * Here let's pretend we have random access. And the values are in the 69 + * constant table fakedata. 70 + */ 71 + for_each_set_bit(j, indio_dev->active_scan_mask, indio_dev->masklength) 72 + data[i++] = fakedata[j]; 83 73 84 74 iio_push_to_buffers_with_timestamp(indio_dev, data, 85 75 iio_get_time_ns(indio_dev));