hwmon: (corsair-cpro) Cache fan target only after a successful command
Subsystems (2)
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.
---
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
@@ -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
[email protected]
AI reviewSashiko 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, subsequentfanN_targetreads 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 leavesfanN_targetreporting 1800. A failed request also replaces-ENODATAwhen no target has been successfully set.
Quoted 7 lines
Update the target cache under the existing mutex only after
send_usb_cmd()succeeds, asset_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")Signed-off-by Baek Kyu, Kim <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 7 lines · Kim
set_target()updates the cached fan target before sending the command. If the command fails, subsequentfanN_targetreads 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 leavesfanN_targetreporting 1800. A failed request also replaces-ENODATAwhen no target has been successfully set.
Quoted 7 lines
Update the target cache under the existing mutex only after
send_usb_cmd()succeeds, asset_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")Signed-off-by Baek Kyu, Kim <[email protected]>
Applied.
Thanks,
Guenter