From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Jiri Kosina" <jikos@kernel.org>,
"Benjamin Tissoires" <bentiss@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Julia Lawall" <Julia.Lawall@inria.fr>,
"Nicolas Palix" <nicolas.palix@imag.fr>,
"Filipe Laíns" <lains@riseup.net>,
"Bastien Nocera" <hadess@hadess.net>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, cocci@inria.fr
Subject: [PATCH 13/21] HID: microsoft: move FF initialization to .input_configured()
Date: Mon, 03 Aug 2026 11:46:38 -0700 [thread overview]
Message-ID: <20260803-hid-ff-input-configured-v1-13-1dc9bbacd88c@gmail.com> (raw)
In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com>
The driver currently initializes force-feedback in its probe() function
after calling hid_hw_start(). This is racy as the input device is
already registered and visible to userspace at that point.
Move the FF initialization to the .input_configured() callback to ensure
the device is fully prepared before registration.
Assisted-by: Gemini:gemini-3.1-pro
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/hid/hid-microsoft.c | 38 ++++++++------------------------------
1 file changed, 8 insertions(+), 30 deletions(-)
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
index 18ac21c0bcb2..a7d3493a6141 100644
--- a/drivers/hid/hid-microsoft.c
+++ b/drivers/hid/hid-microsoft.c
@@ -323,22 +323,17 @@ static int ms_play_effect(struct input_dev *dev, void *data,
return 0;
}
-static int ms_init_ff(struct hid_device *hdev)
+static int ms_input_configured(struct hid_device *hdev, struct hid_input *hidinput)
{
- struct hid_input *hidinput;
- struct input_dev *input_dev;
struct ms_data *ms = hid_get_drvdata(hdev);
-
- if (list_empty(&hdev->inputs)) {
- hid_err(hdev, "no inputs found\n");
- return -ENODEV;
- }
- hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
- input_dev = hidinput->input;
+ struct input_dev *input_dev = hidinput->input;
if (!(ms->quirks & MS_QUIRK_FF))
return 0;
+ if (!list_is_first(&hidinput->list, &hdev->inputs))
+ return 0;
+
ms->hdev = hdev;
INIT_WORK(&ms->ff_worker, ms_ff_worker);
@@ -352,16 +347,6 @@ static int ms_init_ff(struct hid_device *hdev)
return input_ff_create_memless(input_dev, NULL, ms_play_effect);
}
-static void ms_remove_ff(struct hid_device *hdev)
-{
- struct ms_data *ms = hid_get_drvdata(hdev);
-
- if (!(ms->quirks & MS_QUIRK_FF))
- return;
-
- cancel_work_sync(&ms->ff_worker);
-}
-
static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
unsigned long quirks = id->driver_data;
@@ -385,29 +370,21 @@ 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)
- hid_err(hdev, "could not initialize ff, continuing anyway");
-
return 0;
-err_free:
- return ret;
}
-
static void ms_remove(struct hid_device *hdev)
{
hid_hw_stop(hdev);
- ms_remove_ff(hdev);
}
static const struct hid_device_id ms_devices[] = {
@@ -469,6 +446,7 @@ static struct hid_driver ms_driver = {
.report_fixup = ms_report_fixup,
.input_mapping = ms_input_mapping,
.input_mapped = ms_input_mapped,
+ .input_configured = ms_input_configured,
.event = ms_event,
.probe = ms_probe,
.remove = ms_remove,
--
2.55.0.629.g250fe7f194-goog
next prev parent reply other threads:[~2026-08-03 18:46 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 18:46 [PATCH 00/21] HID: fix racy force feedback initialization via .input_configured() Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 01/21] HID: core: automatically initialize generic FF if no other FF is present Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 02/21] HID: add documentation and Coccinelle script for FF registration race Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 03/21] HID: axff: move FF initialization to .input_configured() Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 04/21] HID: betop: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 05/21] HID: bigben: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 06/21] HID: dragonrise: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 07/21] HID: emsff: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 08/21] HID: gaff: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 09/21] HID: stadia: use open/close to manage workqueue lifecycle Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 10/21] HID: stadia: move FF initialization to .input_configured() Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 11/21] HID: holtek: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 12/21] HID: move generic FF initialization into hidinput_connect() Dmitry Torokhov
2026-08-03 18:46 ` Dmitry Torokhov [this message]
2026-08-03 18:46 ` [PATCH 14/21] HID: pantherlord: move FF initialization to .input_configured() Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 15/21] HID: thrustmaster: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 16/21] HID: zeroplus: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 17/21] HID: mayflash: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 18/21] HID: smartjoyplus: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 19/21] HID: megaworld: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 20/21] HID: logitech-hidpp: " Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 21/21] HID: haptic: move FF initialization into .input_configured() Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260803-hid-ff-input-configured-v1-13-1dc9bbacd88c@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=Julia.Lawall@inria.fr \
--cc=bentiss@kernel.org \
--cc=cocci@inria.fr \
--cc=corbet@lwn.net \
--cc=hadess@hadess.net \
--cc=jikos@kernel.org \
--cc=lains@riseup.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.palix@imag.fr \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox