Re: [PATCH v2 1/4] staging: iio: adt7316: refactor temperature calculation logic
From: Jonathan Cameron
Date: Sat Mar 07 2026 - 06:34:13 EST
On Thu, 05 Mar 2026 23:16:58 -0800
Michael Harris <michaelharriscode@xxxxxxxxx> wrote:
> Replace the manual sign manipulation with sign_extend32() and change the
> affected variable from u16 to s32 to properly handle negative values.
>
> Resolve a logic error where the sign bit was being checked at bit 10
> instead of bit 9 for a 10-bit value.
>
> Convert the data variable to be in centidegrees celsius (0.25 C per bit)
> so we can use simple division and modulo for sysfs_emit() instead of the
> convoluted bit shifting and masking.
>
> Signed-off-by: Michael Harris <michaelharriscode@xxxxxxxxx>
As Andy noted needs a fixes tag.
> ---
> drivers/staging/iio/addac/adt7316.c | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c
> index 8a9a8262c2bec34f3c3e79d8174f492b9a23fb70..1412808c50c76a68b5771a25c46dd3308c5cbcdb 100644
> --- a/drivers/staging/iio/addac/adt7316.c
> +++ b/drivers/staging/iio/addac/adt7316.c
> @@ -155,9 +155,12 @@
> * ADT7316 value masks
> */
> #define ADT7316_VALUE_MASK 0xfff
> -#define ADT7316_T_VALUE_SIGN 0x400
> #define ADT7316_T_VALUE_FLOAT_OFFSET 2
> -#define ADT7316_T_VALUE_FLOAT_MASK 0x2
> +
> +/*
> + * ADT7316 hardware constants
> + */
> +#define ADT7316_TEMP_CENTIDEG_PER_BIT 25
As it's only used in one place, I'd think just use the numeric value down there
and if you feel it needs more background, add a comment there.