Skip to contentSkip to conversation

hwmon: (corsair-cpro) Cache fan target only after a successful command

PATCH Applied Baek Kyu, Kim 3 participants 3 messages Oct 20 – Oct 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (corsair-cpro) Cache fan target only after a successful command

set_target() updates the cached fan target before sending the command. If the command fails, subsequent fanN_target reads report the failed request instead of the previous value. For example, after successfully setting 1200 RPM, a rejected request for 1800 RPM returns an error but leaves fanN_target reporting 1800. A failed request also replaces -ENODATA when no target has been successfully set.

Update the target cache under the existing mutex only after send_usb_cmd() succeeds, as set_pwm() already does when invalidating the target. Preserve the previous cached value and return the original error on failure.

Fixes 40c3a4454225 ("hwmon: add Corsair Commander Pro driver")

---
Tested under ARM64 QEMU with an emulated HID transport through the actual corsair-cpro driver and hwmon sysfs. Set fan1_target to 1200, then reject the next 1800 request with -EIO before applying it. Before the fix, the write fails but readback returns 1800; with the fix, readback remains 1200. No physical hardware was tested.

 drivers/hwmon/corsair-cpro.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/corsair-cpro.c +2 -1
index c09645152613..f9e8b7a0d70a 100644
@@ -214,10 +214,11 @@ static int set_target(struct ccp_device *ccp, int channel, long val)
 	int ret;
 
 	val = clamp_val(val, 0, 0xFFFF);
-	ccp->target[channel] = val;
 
 	mutex_lock(&ccp->mutex);
 	ret = send_usb_cmd(ccp, CTL_SET_FAN_TARGET, channel, val >> 8, val);
+	if (!ret)
+		ccp->target[channel] = val;
 
 	mutex_unlock(&ccp->mutex);
 	return ret;

base-commit: 58161ead29e50d70a317ea26b472e0c7508e69da

Signature · 1 line
2.55.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

set_target() updates the cached fan target before sending the command. If the command fails, subsequent fanN_target reads report the failed request instead of the previous value. For example, after successfully setting 1200 RPM, a rejected request for 1800 RPM returns an error but leaves fanN_target reporting 1800. A failed request also replaces -ENODATA when no target has been successfully set.

Quoted 7 lines

Update the target cache under the existing mutex only after send_usb_cmd() succeeds, as set_pwm() already does when invalidating the target. Preserve the previous cached value and return the original error on failure.

Fixes 40c3a4454225 ("hwmon: add Corsair Commander Pro driver")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#2 lore raw
In reply to Baek Kyu, Kim
Quoted 7 lines · Kim

set_target() updates the cached fan target before sending the command. If the command fails, subsequent fanN_target reads report the failed request instead of the previous value. For example, after successfully setting 1200 RPM, a rejected request for 1800 RPM returns an error but leaves fanN_target reporting 1800. A failed request also replaces -ENODATA when no target has been successfully set.

Quoted 7 lines

Update the target cache under the existing mutex only after send_usb_cmd() succeeds, as set_pwm() already does when invalidating the target. Preserve the previous cached value and return the original error on failure.

Fixes 40c3a4454225 ("hwmon: add Corsair Commander Pro driver")

Applied.

Thanks,
Guenter