Skip to contentSkip to conversation

hwmon: (gigabyte_waterforce) Mark status report as received under a spinlock

PATCH In review Aleksa Savic 2 participants 2 messages Dec 19, 2023 – Jan 8, 2024

Subsystems (2)
lore
Share & tools
lore

Aleksa Savic

author maintainer
#0 lore raw

PATCH 1/1 hwmon: (gigabyte_waterforce) Mark status report as received under a spinlock

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")

---
Does the above make sense? The raw event parsing is a softirq AFAIK and presumably could run on a different CPU in parallel to a waterforce_get_status() call.

Appreciate thoughts on this.

---
 drivers/hwmon/gigabyte_waterforce.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hwmon/gigabyte_waterforce.c +2 -0
index 1799377fc2f1..85e523775714 100644
@@ -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;
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 9 lines · Aleksa Savic

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.

Quoted 8 lines
Fixes d5939a793693 ("hwmon: Add driver for Gigabyte AORUS Waterforce AIO coolers")

---
Does the above make sense? The raw event parsing is a softirq AFAIK and presumably could run on a different CPU in parallel to a waterforce_get_status() call.

Appreciate thoughts on this.

I think it does. Applied.

Thanks,
Guenter

Quoted 19 lines
---
 drivers/hwmon/gigabyte_waterforce.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hwmon/gigabyte_waterforce.c +2 -0
index 1799377fc2f1..85e523775714 100644
@@ -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;