All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] hwmon: (scpi-hwmon) shows the negative temperature properly
@ 2021-05-21 12:42 Riwen Lu
  2021-05-21 14:43 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Riwen Lu @ 2021-05-21 12:42 UTC (permalink / raw)
  To: jdelvare, linux; +Cc: linux-hwmon, linux-kernel, Riwen Lu, Xin Chen

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>
---
 drivers/hwmon/scpi-hwmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/scpi-hwmon.c b/drivers/hwmon/scpi-hwmon.c
index 25aac40f2764..583a600bc82d 100644
--- a/drivers/hwmon/scpi-hwmon.c
+++ b/drivers/hwmon/scpi-hwmon.c
@@ -99,7 +99,7 @@ scpi_show_sensor(struct device *dev, struct device_attribute *attr, char *buf)
 
 	scpi_scale_reading(&value, sensor);
 
-	return sprintf(buf, "%llu\n", value);
+	return sprintf(buf, "%lld\n", value);
 }
 
 static ssize_t
-- 
2.25.1


No virus found
		Checked by Hillstone Network AntiVirus

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] hwmon: (scpi-hwmon) shows the negative temperature properly
  2021-05-21 12:42 [PATCH v1] hwmon: (scpi-hwmon) shows the negative temperature properly Riwen Lu
@ 2021-05-21 14:43 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2021-05-21 14:43 UTC (permalink / raw)
  To: Riwen Lu, jdelvare; +Cc: linux-hwmon, linux-kernel, Xin Chen

On 5/21/21 5:42 AM, Riwen Lu wrote:
> 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>

What did you test ? Did you really manage to run the system
in such an environment ?

> ---
>   drivers/hwmon/scpi-hwmon.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/scpi-hwmon.c b/drivers/hwmon/scpi-hwmon.c
> index 25aac40f2764..583a600bc82d 100644
> --- a/drivers/hwmon/scpi-hwmon.c
> +++ b/drivers/hwmon/scpi-hwmon.c
> @@ -99,7 +99,7 @@ scpi_show_sensor(struct device *dev, struct device_attribute *attr, char *buf)
>   
>   	scpi_scale_reading(&value, sensor);
>   
> -	return sprintf(buf, "%llu\n", value);
> +	return sprintf(buf, "%lld\n", value);

'value' is declared as u64, not as s64.
I can not evaluate what the firmware actually reports. The API
reports an u64. Do you have any evidence for your claim that
it returns a signed value under any circumstances ?

On top of that, your change affects not only temperature values,
but all attributes. It is highly unlikely that the firmware would
report negative power or energy values. It is, however, possible
that energy values have the upper bit of an u64 set after a
long runtime. Your change would result in a negative energy value
if that is ever the case.

Guenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-21 14:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21 12:42 [PATCH v1] hwmon: (scpi-hwmon) shows the negative temperature properly Riwen Lu
2021-05-21 14:43 ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.