Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (f71882fg) Fix negative temperature

All temperature of Fintek superio hwmonitor that using 1-byte reg will use
2's complement.

In show_temp()
temp = data->temp[nr] * 1000;

When data->temp[nr] read as 255, it indicate -1C, but this code will report
255C to userspace. It'll be ok when change to:
temp = ((s8)data->temp[nr]) * 1000;

Signed-off-by: Ji-Ze Hong (Peter Hong) <hpeter+linux_kernel@gmail.com>
Link: https://lore.kernel.org/r/20220418090706.6339-1-hpeter+linux_kernel@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Ji-Ze Hong (Peter Hong) and committed by
Guenter Roeck
4aaaaf0f 4d0d5c35

+3 -2
+3 -2
drivers/hwmon/f71882fg.c
··· 1578 1578 temp *= 125; 1579 1579 if (sign) 1580 1580 temp -= 128000; 1581 - } else 1582 - temp = data->temp[nr] * 1000; 1581 + } else { 1582 + temp = ((s8)data->temp[nr]) * 1000; 1583 + } 1583 1584 1584 1585 return sprintf(buf, "%d\n", temp); 1585 1586 }