Skip to contentSkip to conversation

HID: microsoft: add a call hid_hw_stop() in probe()

PATCH In review Jeongjun Park 2 participants 3 messages Jul 16, 2025 – Jul 17, 2025 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: microsoft: add a call hid_hw_stop() in probe()

If hid_hw_start() succeeds but ms_init_ff() fails, it will return without calling hid_hw_stop(), which will cause a memory leak. So to prevent this, we need to change probe() to call hid_hw_stop().

Fixes 73c5b254c365 ("HID: microsoft: Add rumble support for Xbox One S controller")
---
 drivers/hid/hid-microsoft.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/hid/hid-microsoft.c +8 -4
index 18ac21c0bcb2..a27ea59a1bef 100644
@@ -385,22 +385,26 @@ static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	ret = hid_parse(hdev);
 	if (ret) {
 		hid_err(hdev, "parse failed\n");
-		goto err_free;
+		return ret;
 	}
 
 	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ?
 				HID_CONNECT_HIDINPUT_FORCE : 0));
 	if (ret) {
 		hid_err(hdev, "hw start failed\n");
-		goto err_free;
+		return ret;
 	}
 
 	ret = ms_init_ff(hdev);
-	if (ret)
+	if (ret) {
 		hid_err(hdev, "could not initialize ff, continuing anyway");
+		goto err_hw_stop;
+	}
 
 	return 0;
-err_free:
+
+err_hw_stop:
+	hid_hw_stop(hdev);
 	return ret;
 }
 

--

#1 lore raw
Quoted 5 lines · Jeongjun Park

If hid_hw_start() succeeds but ms_init_ff() fails, it will return without calling hid_hw_stop(), which will cause a memory leak. So to prevent this, we need to change probe() to call hid_hw_stop().

If I recall correctly (and it's been a _long_ time since I've looked at this code) we intentionally didn't call hid_hw_stop() so that you'd still have a functional device even if FF feature initialization failed. What's the leak mechanism here?

Quoted 42 lines
Fixes 73c5b254c365 ("HID: microsoft: Add rumble support for Xbox One S controller")
---
 drivers/hid/hid-microsoft.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/hid/hid-microsoft.c +8 -5
index 18ac21c0bcb2..a27ea59a1bef 100644
@@ -385,22 +385,26 @@ static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
        ret = hid_parse(hdev);
        if (ret) {
                hid_err(hdev, "parse failed\n");
-               goto err_free;
+               return ret;
        }
 
        ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ?
                                HID_CONNECT_HIDINPUT_FORCE : 0));
        if (ret) {
                hid_err(hdev, "hw start failed\n");
-               goto err_free;
+               return ret;
        }
 
        ret = ms_init_ff(hdev);
-       if (ret)
+       if (ret) {
                hid_err(hdev, "could not initialize ff, continuing anyway");
+               goto err_hw_stop;
+       }
 
        return 0;
-err_free:
+
+err_hw_stop:
+       hid_hw_stop(hdev);
        return ret;
 }
 
--
#2 lore raw

Hello,

Quoted 8 lines · Andrey Smirnov
Quoted 5 lines · Jeongjun Park

If hid_hw_start() succeeds but ms_init_ff() fails, it will return without calling hid_hw_stop(), which will cause a memory leak. So to prevent this, we need to change probe() to call hid_hw_stop().

Quoted 5 lines

If I recall correctly (and it's been a _long_ time since I've looked at this code) we intentionally didn't call hid_hw_stop() so that you'd still have a functional device even if FF feature initialization failed. What's the leak mechanism here?

I misinterpreted the code.

Thanks for letting me know that ms_init_ff() is designed not to stop the HW if it fails!

Regards,

Jeongjun Park