Commit c8f14e2b authored by Yury Norov's avatar Yury Norov
Browse files

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: default avatarYury Norov <yury.norov@gmail.com>
parent 3a351118
Loading
Loading
Loading
Loading
+19 −29
Original line number Original line Diff line number Diff line
@@ -45,41 +45,31 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
{
{
	struct iio_poll_func *pf = p;
	struct iio_poll_func *pf = p;
	struct iio_dev *indio_dev = pf->indio_dev;
	struct iio_dev *indio_dev = pf->indio_dev;
	int i = 0, j;
	u16 *data;
	u16 *data;


	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
	if (!data)
	if (!data)
		goto done;
		goto done;


	if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) {
	/*
	/*
	 * Three common options here:
	 * Three common options here:
		 * hardware scans: certain combinations of channels make
	 * hardware scans:
		 *   up a fast read.  The capture will consist of all of them.
	 *   certain combinations of channels make up a fast read. The capture
		 *   Hence we just call the grab data function and fill the
	 *   will consist of all of them. Hence we just call the grab data
		 *   buffer without processing.
	 *   function and fill the buffer without processing.
		 * software scans: can be considered to be random access
	 * software scans:
		 *   so efficient reading is just a case of minimal bus
	 *   can be considered to be random access so efficient reading is just
		 *   transactions.
	 *   a case of minimal bus transactions.
	 * software culled hardware scans:
	 * software culled hardware scans:
		 *   occasionally a driver may process the nearest hardware
	 *   occasionally a driver may process the nearest hardware scan to avoid
		 *   scan to avoid storing elements that are not desired. This
	 *   storing elements that are not desired. This is the fiddliest option
		 *   is the fiddliest option by far.
	 *   by far.
		 * Here let's pretend we have random access. And the values are
	 * Here let's pretend we have random access. And the values are in the
		 * in the constant table fakedata.
	 * constant table fakedata.
	 */
	 */
		int i, j;
	for_each_set_bit(j, indio_dev->active_scan_mask, indio_dev->masklength)

		data[i++] = fakedata[j];
		for (i = 0, j = 0;
		     i < bitmap_weight(indio_dev->active_scan_mask,
				       indio_dev->masklength);
		     i++, j++) {
			j = find_next_bit(indio_dev->active_scan_mask,
					  indio_dev->masklength, j);
			/* random access read from the 'device' */
			data[i] = fakedata[j];
		}
	}


	iio_push_to_buffers_with_timestamp(indio_dev, data,
	iio_push_to_buffers_with_timestamp(indio_dev, data,
					   iio_get_time_ns(indio_dev));
					   iio_get_time_ns(indio_dev));