summaryrefslogtreecommitdiff
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorRiwen Lu <luriwen@kylinos.cn>2021-06-04 06:09:59 +0300
committerSasha Levin <sashal@kernel.org>2021-06-30 15:48:52 +0300
commit23f97d0f3176636dbb2ffd10a1a03efd70be5290 (patch)
tree1a2d232d13ea5989e9d928f4fe72b14b802fb5fd /drivers/hwmon
parent596ca7e388c30052a179d0e641fcfb24ec744988 (diff)
downloadlinux-23f97d0f3176636dbb2ffd10a1a03efd70be5290.tar.xz
hwmon: (scpi-hwmon) shows the negative temperature properly
[ Upstream commit 78d13552346289bad4a9bf8eabb5eec5e5a321a5 ] The scpi hwmon shows the sub-zero temperature in an unsigned integer, which would confuse the users when the machine works in low temperature environment. This shows the sub-zero temperature in an signed value and users can get it properly from sensors. Signed-off-by: Riwen Lu <luriwen@kylinos.cn> Tested-by: Xin Chen <chenxin@kylinos.cn> Link: https://lore.kernel.org/r/20210604030959.736379-1-luriwen@kylinos.cn Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/scpi-hwmon.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/hwmon/scpi-hwmon.c b/drivers/hwmon/scpi-hwmon.c
index 7e49da50bc69..562f3e287297 100644
--- a/drivers/hwmon/scpi-hwmon.c
+++ b/drivers/hwmon/scpi-hwmon.c
@@ -107,6 +107,15 @@ scpi_show_sensor(struct device *dev, struct device_attribute *attr, char *buf)
scpi_scale_reading(&value, sensor);
+ /*
+ * Temperature sensor values are treated as signed values based on
+ * observation even though that is not explicitly specified, and
+ * because an unsigned u64 temperature does not really make practical
+ * sense especially when the temperature is below zero degrees Celsius.
+ */
+ if (sensor->info.class == TEMPERATURE)
+ return sprintf(buf, "%lld\n", (s64)value);
+
return sprintf(buf, "%llu\n", value);
}