diff mbox series

[01/20] iio: core: add accessors 'masklength'

Message ID 20240702-dev-iio-masklength-private-v1-1-98193bf536a6@analog.com (mailing list archive)
State New
Headers show
Series iio: make masklength __private (round 1) | expand

Commit Message

Nuno Sa via B4 Relay July 2, 2024, 4:02 p.m. UTC
From: Nuno Sa <nuno.sa@analog.com>

'masklength' is supposed to be an IIO private member. However, drivers
(often in trigger handlers) need to access it to iterate over the
enabled channels for example (there are other reasons). Hence, a couple
of new accessors are being added:

 * iio_for_each_active_channel() - Iterates over the active channels;
 * iio_get_masklength() - Get length of the channels mask.

The goal of these new accessors is to annotate 'masklength' as private
as soon as all drivers accessing it are converted to use the new
helpers.

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

Comments

Alexandru Ardelean July 3, 2024, 6:10 a.m. UTC | #1
On Tue, Jul 2, 2024 at 7:02 PM Nuno Sa via B4 Relay
<devnull+nuno.sa.analog.com@kernel.org> wrote:
>
> From: Nuno Sa <nuno.sa@analog.com>
>
> 'masklength' is supposed to be an IIO private member. However, drivers
> (often in trigger handlers) need to access it to iterate over the
> enabled channels for example (there are other reasons). Hence, a couple
> of new accessors are being added:
>
>  * iio_for_each_active_channel() - Iterates over the active channels;
>  * iio_get_masklength() - Get length of the channels mask.
>
> The goal of these new accessors is to annotate 'masklength' as private
> as soon as all drivers accessing it are converted to use the new
> helpers.
>

Reviewed-by: Alexandru Ardelean <aardelean@baylibre.com>

> Signed-off-by: Nuno Sa <nuno.sa@analog.com>
> ---
>  include/linux/iio/iio.h | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index 894309294182d..dd6bbc468283e 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -855,6 +855,24 @@ static inline const struct iio_scan_type
>         return &chan->scan_type;
>  }
>
> +/**
> + * iio_get_masklength - Get length of the channels mask
> + * @indio_dev: the IIO device to get the masklength for
> + */
> +static inline unsigned int iio_get_masklength(const struct iio_dev *indio_dev)
> +{
> +       return indio_dev->masklength;
> +}
> +
> +/**
> + * iio_for_each_active_channel - Iterated over active channels
> + * @indio_dev: the IIO device
> + * @chan: Holds the index of the enabled channel
> + */
> +#define iio_for_each_active_channel(indio_dev, chan) \
> +       for_each_set_bit((chan), (indio_dev)->active_scan_mask, \
> +                        iio_get_masklength(indio_dev))
> +
>  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,
>
> --
> 2.45.2
>
>
>
diff mbox series

Patch

diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 894309294182d..dd6bbc468283e 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -855,6 +855,24 @@  static inline const struct iio_scan_type
 	return &chan->scan_type;
 }
 
+/**
+ * iio_get_masklength - Get length of the channels mask
+ * @indio_dev: the IIO device to get the masklength for
+ */
+static inline unsigned int iio_get_masklength(const struct iio_dev *indio_dev)
+{
+	return indio_dev->masklength;
+}
+
+/**
+ * iio_for_each_active_channel - Iterated over active channels
+ * @indio_dev: the IIO device
+ * @chan: Holds the index of the enabled channel
+ */
+#define iio_for_each_active_channel(indio_dev, chan) \
+	for_each_set_bit((chan), (indio_dev)->active_scan_mask, \
+			 iio_get_masklength(indio_dev))
+
 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,