]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
hwmon: (scpi-hwmon) shows the negative temperature properly
authorRiwen Lu <luriwen@kylinos.cn>
Fri, 4 Jun 2021 03:09:59 +0000 (11:09 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 13 Aug 2021 07:28:56 +0000 (09:28 +0200)
BugLink: https://bugs.launchpad.net/bugs/1936688
[ 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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/hwmon/scpi-hwmon.c

index 25aac40f2764aec4b3223b46d6d3919773b8b4e7..919877970ae3b1c342b7a37ce7da2ffac1c45204 100644 (file)
@@ -99,6 +99,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);
 }