* [PATCH] HID: microsoft: add a call hid_hw_stop() in probe()
@ 2025-07-16 17:22 Jeongjun Park
2025-07-16 21:08 ` Andrey Smirnov
0 siblings, 1 reply; 3+ messages in thread
From: Jeongjun Park @ 2025-07-16 17:22 UTC (permalink / raw)
To: jikos, bentiss
Cc: andrew.smirnov, juha.kuikka, linux-input, linux-kernel,
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().
Fixes: 73c5b254c365 ("HID: microsoft: Add rumble support for Xbox One S controller")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
drivers/hid/hid-microsoft.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
index 18ac21c0bcb2..a27ea59a1bef 100644
--- a/drivers/hid/hid-microsoft.c
+++ b/drivers/hid/hid-microsoft.c
@@ -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;
}
--
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] HID: microsoft: add a call hid_hw_stop() in probe()
2025-07-16 17:22 [PATCH] HID: microsoft: add a call hid_hw_stop() in probe() Jeongjun Park
@ 2025-07-16 21:08 ` Andrey Smirnov
2025-07-17 2:58 ` Jeongjun Park
0 siblings, 1 reply; 3+ messages in thread
From: Andrey Smirnov @ 2025-07-16 21:08 UTC (permalink / raw)
To: Jeongjun Park; +Cc: jikos, bentiss, juha.kuikka, linux-input, linux-kernel
On Wed, Jul 16, 2025 at 10:22 AM Jeongjun Park <aha310510@gmail.com> wrote:
>
> 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?
> Fixes: 73c5b254c365 ("HID: microsoft: Add rumble support for Xbox One S controller")
> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
> ---
> drivers/hid/hid-microsoft.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
> index 18ac21c0bcb2..a27ea59a1bef 100644
> --- a/drivers/hid/hid-microsoft.c
> +++ b/drivers/hid/hid-microsoft.c
> @@ -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;
> }
>
> --
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] HID: microsoft: add a call hid_hw_stop() in probe()
2025-07-16 21:08 ` Andrey Smirnov
@ 2025-07-17 2:58 ` Jeongjun Park
0 siblings, 0 replies; 3+ messages in thread
From: Jeongjun Park @ 2025-07-17 2:58 UTC (permalink / raw)
To: Andrey Smirnov; +Cc: jikos, bentiss, juha.kuikka, linux-input, linux-kernel
Hello,
Andrey Smirnov <andrew.smirnov@gmail.com> wrote:
>
> On Wed, Jul 16, 2025 at 10:22 AM Jeongjun Park <aha310510@gmail.com> wrote:
> >
> > 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?
>
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-17 2:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16 17:22 [PATCH] HID: microsoft: add a call hid_hw_stop() in probe() Jeongjun Park
2025-07-16 21:08 ` Andrey Smirnov
2025-07-17 2:58 ` Jeongjun Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).