All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 1/1] hwmon:(f71882fg) Fix minus temperature
@ 2022-04-18  9:07 Ji-Ze Hong (Peter Hong)
  2022-04-18 15:15 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Ji-Ze Hong (Peter Hong) @ 2022-04-18  9:07 UTC (permalink / raw)
  To: linux
  Cc: Menghui_Wu, fercerpav, peter_hong, acelan.kao, linux-hwmon,
	Ji-Ze Hong (Peter Hong)

All temperature of Fintek superio hwmonitor that using 1-byte reg will use
2's complement.

In show_temp()
	temp = data->temp[nr] * 1000;

When data->temp[nr] read as 255, it indicate -1C, but this code will report
255C to userspace. It'll be ok when change to:
	temp = ((s8)data->temp[nr]) * 1000;

Signed-off-by: Ji-Ze Hong (Peter Hong) <hpeter+linux_kernel@gmail.com>
---
 drivers/hwmon/f71882fg.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index 938a8b9ec70d..6830e029995d 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -1578,8 +1578,9 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
 		temp *= 125;
 		if (sign)
 			temp -= 128000;
-	} else
-		temp = data->temp[nr] * 1000;
+	} else {
+		temp = ((s8)data->temp[nr]) * 1000;
+	}
 
 	return sprintf(buf, "%d\n", temp);
 }
-- 
2.17.1


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

* Re: [PATCH V2 1/1] hwmon:(f71882fg) Fix minus temperature
  2022-04-18  9:07 [PATCH V2 1/1] hwmon:(f71882fg) Fix minus temperature Ji-Ze Hong (Peter Hong)
@ 2022-04-18 15:15 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2022-04-18 15:15 UTC (permalink / raw)
  To: Ji-Ze Hong (Peter Hong)
  Cc: Menghui_Wu, fercerpav, peter_hong, acelan.kao, linux-hwmon,
	Ji-Ze Hong (Peter Hong)

On Mon, Apr 18, 2022 at 05:07:06PM +0800, Ji-Ze Hong (Peter Hong) wrote:
> All temperature of Fintek superio hwmonitor that using 1-byte reg will use
> 2's complement.
> 
> In show_temp()
> 	temp = data->temp[nr] * 1000;
> 
> When data->temp[nr] read as 255, it indicate -1C, but this code will report
> 255C to userspace. It'll be ok when change to:
> 	temp = ((s8)data->temp[nr]) * 1000;
> 
> Signed-off-by: Ji-Ze Hong (Peter Hong) <hpeter+linux_kernel@gmail.com>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/f71882fg.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
> index 938a8b9ec70d..6830e029995d 100644
> --- a/drivers/hwmon/f71882fg.c
> +++ b/drivers/hwmon/f71882fg.c
> @@ -1578,8 +1578,9 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
>  		temp *= 125;
>  		if (sign)
>  			temp -= 128000;
> -	} else
> -		temp = data->temp[nr] * 1000;
> +	} else {
> +		temp = ((s8)data->temp[nr]) * 1000;
> +	}
>  
>  	return sprintf(buf, "%d\n", temp);
>  }

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

end of thread, other threads:[~2022-04-18 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-18  9:07 [PATCH V2 1/1] hwmon:(f71882fg) Fix minus temperature Ji-Ze Hong (Peter Hong)
2022-04-18 15:15 ` 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.