[PATCH v2 07/10] HID: steam: Rearrange deinitialization sequence
From: Vicki Pfau <hidden>
Date: 2026-07-07 23:33:53
Subsystem:
hid core layer, the rest · Maintainers:
Jiri Kosina, Benjamin Tissoires, Linus Torvalds
This fixes a narrow window during the deinitialization where callbacks could still be scheduled during cleanup that would then have a dangling pointer to the now-freed steam struct. Signed-off-by: Vicki Pfau <redacted> --- drivers/hid/hid-steam.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c
index 3f1dbdcad23c..296ced2989a4 100644
--- a/drivers/hid/hid-steam.c
+++ b/drivers/hid/hid-steam.c@@ -1327,6 +1327,7 @@ static int steam_probe(struct hid_device *hdev, { struct steam_device *steam; int ret; + unsigned long flags; ret = hid_parse(hdev); if (ret) {
@@ -1417,6 +1418,10 @@ static int steam_probe(struct hid_device *hdev, err_destroy: hid_destroy_device(steam->client_hdev); err_steam_unregister: + spin_lock_irqsave(&steam->lock, flags); + steam->client_opened = 0; + spin_unlock_irqrestore(&steam->lock, flags); + cancel_work_sync(&steam->work_connect); if (steam->connected) steam_unregister(steam); err_hw_close:
@@ -1424,7 +1429,6 @@ static int steam_probe(struct hid_device *hdev, err_hw_stop: hid_hw_stop(hdev); err_cancel_work: - cancel_work_sync(&steam->work_connect); cancel_delayed_work_sync(&steam->mode_switch); cancel_work_sync(&steam->rumble_work); cancel_delayed_work_sync(&steam->coalesce_rumble_work);
@@ -1435,6 +1439,7 @@ static int steam_probe(struct hid_device *hdev, static void steam_remove(struct hid_device *hdev) { struct steam_device *steam = hid_get_drvdata(hdev); + unsigned long flags; if (!steam || hdev->group == HID_GROUP_STEAM) { hid_hw_stop(hdev);
@@ -1442,18 +1447,20 @@ static void steam_remove(struct hid_device *hdev) } hid_destroy_device(steam->client_hdev); - cancel_delayed_work_sync(&steam->mode_switch); - cancel_work_sync(&steam->work_connect); - cancel_work_sync(&steam->rumble_work); - cancel_delayed_work_sync(&steam->coalesce_rumble_work); steam->client_hdev = NULL; + hid_hw_close(hdev); + spin_lock_irqsave(&steam->lock, flags); steam->client_opened = 0; + spin_unlock_irqrestore(&steam->lock, flags); + cancel_work_sync(&steam->work_connect); if (steam->quirks & STEAM_QUIRK_WIRELESS) { hid_info(hdev, "Steam wireless receiver disconnected"); } - hid_hw_close(hdev); - hid_hw_stop(hdev); steam_unregister(steam); + cancel_work_sync(&steam->rumble_work); + cancel_delayed_work_sync(&steam->mode_switch); + cancel_delayed_work_sync(&steam->coalesce_rumble_work); + hid_hw_stop(hdev); } static void steam_do_connect_event(struct steam_device *steam, bool connected)
--
2.54.0