Re: [PATCH v2 2/2] hwmon: (max6621) fix negative temperature offset and crit readings

Guenter Roeck <[email protected]>
Newsgroups org.kernel.vger.linux-hwmon,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
On Mon, Aug 10, 2026 at 11:28:39AM +0700, Cong Nguyen wrote:
> max6621_read() reads the CONFIG2 offset and the critical alert threshold
> registers into a u32 and scales them without sign extension:
> 
> 	/* offset */ *val = (regval >> MAX6621_REG_TEMP_SHIFT) * 1000L;
> 	/* crit   */ *val = regval * 1000L;
> 
> Both attributes are writable and their write paths clamp to a negative
> minimum and encode negative values, so a value written as negative is read
> back as a large positive number. For example, writing a -10 degrees C
> offset stores max6621_temp_mc2reg(-10000) = (-10 << 6) = 0xfd80; the read
> then computes 0xfd80 >> 6 = 1014 -> 1014000 instead of -10000.
> 
> Cast the register value to s16 before scaling so the read preserves the
> sign the write path encodes. The temperature input path already uses an s8
> intermediate and is left unchanged.
> 
> Fixes: 92b64580f14b ("hwmon: (max6621) Add support for Maxim MAX6621 temperature sensor")
> Cc: [email protected]
> Assisted-by: Claude:claude-opus-4
> Signed-off-by: Cong Nguyen <[email protected]>

Applied.

Thanks,
Guenter
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.