Skip to content

Commit

Permalink
hwmon: (f71882fg) Fix negative temperature
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ji-Ze Hong (Peter Hong) authored and Guenter Roeck committed Apr 18, 2022
1 parent 4d0d5c3 commit 4aaaaf0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/hwmon/f71882fg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1578,8 +1578,9 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
temp *= 125;
if (sign)
temp -= 128000;
} else
temp = data->temp[nr] * 1000;
} else {
temp = ((s8)data->temp[nr]) * 1000;
}

return sprintf(buf, "%d\n", temp);
}
Expand Down

0 comments on commit 4aaaaf0

Please sign in to comment.