Skip to content

Commit

Permalink
hwmon: (scpi-hwmon) shows the negative temperature properly
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Riwen Lu authored and Guenter Roeck committed Jun 9, 2021
1 parent 7656cd2 commit 78d1355
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/hwmon/scpi-hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 78d1355

Please sign in to comment.