public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Riwen Lu <luriwen@kylinos.cn>
Cc: jdelvare@suse.com, linux-hwmon@vger.kernel.org,
	linux-kernel@vger.kernel.org, Xin Chen <chenxin@kylinos.cn>
Subject: Re: [PATCH v3] hwmon: (scpi-hwmon) shows the negative temperature properly
Date: Fri, 4 Jun 2021 04:09:10 -0700	[thread overview]
Message-ID: <20210604110910.GA1446504@roeck-us.net> (raw)
In-Reply-To: <20210604030959.736379-1-luriwen@kylinos.cn>

On Fri, Jun 04, 2021 at 11:09:59AM +0800, 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>

Applied.

Thanks,
Guenter

> ---
> Changes since v1:
> - Add judgment for sensor->info.class. If it is TEMPERATURE situation,
>   return the sensor value as a signed value, otherwise return it as a
>   unsigned value.
> 
> Changes since v2:
> - Add a typecast u64 to s64 when it is a temperature value.
> - Add a comment ahead of the if statement.
> - Remove the unnecessary 'else' statement.
> ---
>  drivers/hwmon/scpi-hwmon.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/hwmon/scpi-hwmon.c b/drivers/hwmon/scpi-hwmon.c
> index 25aac40f2764..919877970ae3 100644
> --- a/drivers/hwmon/scpi-hwmon.c
> +++ b/drivers/hwmon/scpi-hwmon.c
> @@ -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);
>  }
>  

      reply	other threads:[~2021-06-04 11:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04  3:09 [PATCH v3] hwmon: (scpi-hwmon) shows the negative temperature properly Riwen Lu
2021-06-04 11:09 ` Guenter Roeck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210604110910.GA1446504@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=chenxin@kylinos.cn \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luriwen@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox