Skip to contentSkip to conversation

hwmon: corsair-cpro: Read negative temperatures and remove magic values

PATCH Applied Marius Zachmann 2 participants 5 messages Nov 13, 2025

Subsystems (2)
lore
Share & tools
lore

Marius Zachmann

author maintainer
#0 lore raw

cover hwmon: corsair-cpro: Read negative temperatures and remove magic values

- The Commander Pro also allows reading negative temperatures. Adds a conversion to read it correctly.

- Replace two of the magic values in the ccp_device struct with constants.

Marius Zachmann (2):
Read temperature as a signed value.
Replace magic values with constants

 drivers/hwmon/corsair-cpro.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.51.2
author maintainer
#1 lore raw

PATCH 1/2 Read temperature as a signed value.

Convert temperature to s16 to correctly read negative temperatures.

---
 drivers/hwmon/corsair-cpro.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/corsair-cpro.c +2 -2
index b7b911f8359c..6e1c415f3e26 100644
@@ -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;
Signature · 1 line
2.51.2
maintainer Applied
#2 lore raw

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

Quoted 21 lines · Marius Zachmann

Convert temperature to s16 to correctly read negative temperatures.

---
 drivers/hwmon/corsair-cpro.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/corsair-cpro.c +1 -1
index b7b911f8359c..6e1c415f3e26 100644
@@ -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	/*

drivers/hwmon/corsair-cpro.c static int ccp_read(struct device *dev, enum hwmon_sensor_types type, · line 261

Quoted 5 lines
drivers/hwmon/corsair-cpro.c +1 -1
@@ -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

author maintainer
#3 lore raw

PATCH 2/2 Replace magic values with constants

In reply to Marius Zachmann

Replace two magic values in ccp_device with
existing constants.

---
 drivers/hwmon/corsair-cpro.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/corsair-cpro.c +2 -2
index 6e1c415f3e26..e755353dd461 100644
@@ -90,10 +90,10 @@ struct ccp_device {
 	u8 *cmd_buffer;
 	u8 *buffer;
 	int buffer_recv_size; /* number of received bytes in buffer */
-	int target[6];
+	int target[NUM_FANS];
 	DECLARE_BITMAP(temp_cnct, NUM_TEMP_SENSORS);
 	DECLARE_BITMAP(fan_cnct, NUM_FANS);
-	char fan_label[6][LABEL_LENGTH];
+	char fan_label[NUM_FANS][LABEL_LENGTH];
 	u8 firmware_ver[3];
 	u8 bootloader_ver[2];
 };
Signature · 1 line
2.51.2
maintainer Applied
#4 lore raw

Re: [PATCH 2/2] Replace magic values with constants

Quoted 4 lines · Marius Zachmann

Replace two magic values in ccp_device with
existing constants.

Applied. Please watch out for the subject line in the future. It should start with "hwmon: (corsair-cpro)".

Thanks,
Guenter