hwmon: (gigabyte_waterforce) Mark status report as received under a spinlock
authorAleksa Savic <savicaleksa83@gmail.com>
Tue, 19 Dec 2023 14:36:19 +0000 (15:36 +0100)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 8 Jan 2024 15:27:27 +0000 (07:27 -0800)
Through hidraw, userspace can cause a status report to be sent
from the device. The parsing in waterforce_raw_event() may happen in
parallel to a waterforce_get_status() call (which resets the completion
for tracking the report) if it's running on a different CPU where
bottom half interrupts are not disabled.

Add a spinlock around the complete_all() call in waterforce_raw_event()
to prevent race issues.

Fixes: d5939a793693 ("hwmon: Add driver for Gigabyte AORUS Waterforce AIO coolers")
Signed-off-by: Aleksa Savic <savicaleksa83@gmail.com>
Link: https://lore.kernel.org/r/20231219143620.22179-1-savicaleksa83@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/gigabyte_waterforce.c

index 1799377fc2f1fb023d501d1f16d231c3f848f61f..85e5237757142a05b45fdd7006d4c7b2ca61a3c3 100644 (file)
@@ -276,8 +276,10 @@ static int waterforce_raw_event(struct hid_device *hdev, struct hid_report *repo
        priv->duty_input[0] = data[WATERFORCE_FAN_DUTY];
        priv->duty_input[1] = data[WATERFORCE_PUMP_DUTY];
 
+       spin_lock(&priv->status_report_request_lock);
        if (!completion_done(&priv->status_report_received))
                complete_all(&priv->status_report_received);
+       spin_unlock(&priv->status_report_request_lock);
 
        priv->updated = jiffies;