From e2c26431b4e47892378582a414b4bbaa9edf1798 Mon Sep 17 00:00:00 2001 From: "Baek Kyu, Kim" Date: Wed, 21 Oct 2026 01:09:41 +0900 Subject: [PATCH] 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") Cc: stable@vger.kernel.org Signed-off-by: Baek Kyu, Kim Link: https://patch.msgid.link/20261020160941.36787-1-pocj8ur4in@gmail.com Signed-off-by: Guenter Roeck --- drivers/hwmon/corsair-cpro.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/corsair-cpro.c b/drivers/hwmon/corsair-cpro.c index e6d31d367698..6ce5da37de03 100644 --- a/drivers/hwmon/corsair-cpro.c +++ b/drivers/hwmon/corsair-cpro.c @@ -215,10 +215,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;