Re: [PATCH v2 2/4] staging: iio: adt7316: remove shift/offset macros

From: Jonathan Cameron

Date: Sat Mar 07 2026 - 06:30:31 EST


On Thu, 05 Mar 2026 23:16:59 -0800
Michael Harris <michaelharriscode@xxxxxxxxx> wrote:

> Remove shift/offset macros and instead use the corresponding mask with
> FIELD_GET(), FIELD_PREP(), or FIELD_FIT().
>
> In cases where an appropriate mask didn't exist, it was created.
>
> One of the shift/offset macros was used for a convoluted dynamic
> bitfield extraction. In its place, a helper function,
> adt7316_extract_ad_lsb(), was created so the shift/offset could be
> removed.
>
> Signed-off-by: Michael Harris <michaelharriscode@xxxxxxxxx>

> ---
> drivers/staging/iio/addac/adt7316.c | 59 ++++++++++++++++++++++---------------
> 1 file changed, 36 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c
> index 1412808c50c76a68b5771a25c46dd3308c5cbcdb..b8b66f4dd14bb59c3d29fdd569d84f0dd786db9e 100644
> --- a/drivers/staging/iio/addac/adt7316.c
> +++ b/drivers/staging/iio/addac/adt7316.c
> @@ -17,6 +17,7 @@
> #include <linux/i2c.h>
> #include <linux/rtc.h>
> #include <linux/module.h>
> +#include <linux/bitfield.h>
>
> #include <linux/iio/iio.h>
> #include <linux/iio/events.h>
> @@ -31,10 +32,11 @@
> #define ADT7316_LSB_IN_TEMP_VDD 0x3
> #define ADT7316_LSB_IN_TEMP_MASK 0x3
> #define ADT7316_LSB_VDD_MASK 0xC

Convert all masks to GENMASK_U32() rather than just the ones where you
are removing a shift. That will give us more consistent code and
makes sense as part of this patch.


> -#define ADT7316_LSB_VDD_OFFSET 2
> #define ADT7316_LSB_EX_TEMP_AIN 0x4
> -#define ADT7316_LSB_EX_TEMP_MASK 0x3
> -#define ADT7516_LSB_AIN_SHIFT 2
> +#define ADT7316_LSB_EX_TEMP_AIN1_MASK GENMASK_U32(1, 0)
Why GENMASK_U32()? The registers seem to be 8 bit.
I'm not sure we care that much about the extra checks the sized
variant brings but if we do want to use it use the U8() variant.

Jonathan