diff mbox series

[RFC,1/3] iio: core: add new helper to iterate active channels

Message ID 20240612-dev-iio-scan-private-v1-1-7c75c8e3d30b@analog.com (mailing list archive)
State Changes Requested
Headers show
Series iio: add helpers and accessors for active channels and masklength | expand

Commit Message

Nuno Sa June 12, 2024, 2:20 p.m. UTC
Add a new iio_for_each_active_channel() helper to iterate over the
active channels. Also add an helper to access masklength using
ACCESS_PRIVATE(). End goal is to annotate that variable as __private so that
we can get checker warnings if drivers directly access that variable.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 include/linux/iio/iio.h | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 894309294182..a63888746707 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -860,6 +860,12 @@  ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals);
 int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer,
 	int *fract);
 
+#define iio_dev_masklength(indio_dev)	ACCESS_PRIVATE(indio_dev, masklength)
+
+#define iio_for_each_active_channel(indio_dev, bit) \
+	for_each_set_bit((bit), (indio_dev)->active_scan_mask, \
+			 iio_dev_masklength(indio_dev))
+
 /**
  * IIO_DEGREE_TO_RAD() - Convert degree to rad
  * @deg: A value in degree