Re: [PATCH v2] hwmon: (corsair-psu) Fix linear11 calculation

[email protected] Tue, 04 Aug 2026 03:55:42 +0000
Newsgroups org.kernel.vger.linux-hwmon
Message-ID <[email protected]>
> In corsairpsu_linear11_to_int(), the mantissa is extracted using bitwise
> operations and cast to s16 before being shifted left:
>=20
> static int corsairpsu_linear11_to_int(const u16 val, const int scale)
> {
>     ...
>     const int mant =3D (((s16)(val & 0x7ff)) << 5) >> 5;
>     ...
> }
>=20
> Due to C integer promotion rules, the masked value (which is always
> positive) is promoted to a 32-bit integer before the left shift. As a
> result, the sign bit is never extended to bit 31 of the promoted integer.
>=20
> When the device hardware reports a negative temperature in Linear11 format
> [ ... ]
> retaining as much information as possible.
>=20
> Reported-by: Sashiko <[email protected]>
> Cc: Wilken Gottwalt <[email protected]>
> Signed-off-by: Guenter Roeck <[email protected]>

Sashiko has reviewed this patch and found no issues. It looks great!

--=20
Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20260804034811.2385=
[email protected]?part=3D1