[PATCH 1/2] Read temperature as a signed value.

Marius Zachmann posted 2 patches 2 months, 3 weeks ago
[PATCH 1/2] Read temperature as a signed value.
Posted by Marius Zachmann 2 months, 3 weeks ago
Convert temperature to s16 to correctly read negative temperatures.

Signed-off-by: Marius Zachmann <mail@mariuszachmann.de>
---
 drivers/hwmon/corsair-cpro.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/corsair-cpro.c b/drivers/hwmon/corsair-cpro.c
index b7b911f8359c..6e1c415f3e26 100644
--- a/drivers/hwmon/corsair-cpro.c
+++ b/drivers/hwmon/corsair-cpro.c
@@ -40,7 +40,7 @@
 #define CTL_GET_TMP		0x11	/*
 					 * send: byte 1 is channel, rest zero
 					 * rcv:  returns temp for channel in centi-degree celsius
-					 * in bytes 1 and 2
+					 * in bytes 1 and 2 as a two's complement value
 					 * returns 0x11 in byte 0 if no sensor is connected
 					 */
 #define CTL_GET_VOLT		0x12	/*
@@ -258,7 +258,7 @@ static int ccp_read(struct device *dev, enum hwmon_sensor_types type,
 			ret = get_data(ccp, CTL_GET_TMP, channel, true);
 			if (ret < 0)
 				return ret;
-			*val = ret * 10;
+			*val = (s16) ret * 10;
 			return 0;
 		default:
 			break;
-- 
2.51.2
Re: [PATCH 1/2] Read temperature as a signed value.
Posted by Guenter Roeck 2 months, 3 weeks ago
On Thu, Nov 13, 2025 at 11:00:23AM +0100, Marius Zachmann wrote:
> Convert temperature to s16 to correctly read negative temperatures.
> 
> Signed-off-by: Marius Zachmann <mail@mariuszachmann.de>
> ---
>  drivers/hwmon/corsair-cpro.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/corsair-cpro.c b/drivers/hwmon/corsair-cpro.c
> index b7b911f8359c..6e1c415f3e26 100644
> --- a/drivers/hwmon/corsair-cpro.c
> +++ b/drivers/hwmon/corsair-cpro.c
> @@ -40,7 +40,7 @@
>  #define CTL_GET_TMP		0x11	/*
>  					 * send: byte 1 is channel, rest zero
>  					 * rcv:  returns temp for channel in centi-degree celsius
> -					 * in bytes 1 and 2
> +					 * in bytes 1 and 2 as a two's complement value
>  					 * returns 0x11 in byte 0 if no sensor is connected
>  					 */
>  #define CTL_GET_VOLT		0x12	/*
> @@ -258,7 +258,7 @@ static int ccp_read(struct device *dev, enum hwmon_sensor_types type,
>  			ret = get_data(ccp, CTL_GET_TMP, channel, true);
>  			if (ret < 0)
>  				return ret;
> -			*val = ret * 10;
> +			*val = (s16) ret * 10;

checkpatch:

CHECK: No space necessary after a cast

No need to resend, I'll patch that up.

Applied.

Guenter