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

From: Andy Shevchenko

Date: Fri Mar 06 2026 - 09:54:26 EST


On Thu, Mar 05, 2026 at 11:16:59PM -0800, Michael Harris 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.

...

> #include <linux/i2c.h>
> #include <linux/rtc.h>
> #include <linux/module.h>
> +#include <linux/bitfield.h>

Try to squeeze it to make a longest (but sparse AFAICS) ordered list of
inclusions. With given context

#include <linux/bitfield.h>
#include <linux/i2c.h>
#include <linux/rtc.h>
#include <linux/module.h>

gives 3 out of 4 in order.

...

> dac_config = chip->dac_config & (~ADT7316_DA_EN_MODE_MASK);
> - dac_config |= data << ADT7316_DA_EN_MODE_SHIFT;
> + dac_config |= FIELD_PREP(ADT7316_DA_EN_MODE_MASK, data);

FIELD_MODIFY() ?

...

> - data = msb << ADT7316_T_VALUE_FLOAT_OFFSET;
> + data = FIELD_PREP(ADT7316_AD_MSB_MASK, msb);
> data |= lsb & ADT7316_LSB_IN_TEMP_MASK;

Ditto and so on...

--
With Best Regards,
Andy Shevchenko