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 21/21] HID: haptic: move FF initialization into .input_configured()
Date: Mon, 03 Aug 2026 11:46:46 -0700 [thread overview]
Message-ID: <20260803-hid-ff-input-configured-v1-21-1dc9bbacd88c@gmail.com> (raw)
In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com>
Refactor hid_haptic_init() to take a direct pointer to input_dev and
integrate its invocation into hid_haptic_input_configured().
Update hid-multitouch to rely on the refactored callback to perform the
force-feedback initialization during the registration loop. This ensures
that force-feedback capabilities are set up before the input device is
registered and exposed to userspace, closing the registration race.
Assisted-by: Gemini:gemini-3.1-pro
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/hid/hid-haptic.c | 45 +++++++++++++++++---------------------------
drivers/hid/hid-haptic.h | 6 ++++--
drivers/hid/hid-multitouch.c | 10 +---------
3 files changed, 22 insertions(+), 39 deletions(-)
diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c
index deadab28cdbe..5d365a9767dd 100644
--- a/drivers/hid/hid-haptic.c
+++ b/drivers/hid/hid-haptic.c
@@ -82,16 +82,24 @@ int hid_haptic_input_configured(struct hid_device *hdev,
struct hid_haptic_device *haptic,
struct hid_input *hi)
{
+ int error;
- if (hi->application == HID_DG_TOUCHPAD) {
- if (haptic->auto_trigger_report &&
- haptic->manual_trigger_report) {
- __set_bit(INPUT_PROP_PRESSUREPAD, hi->input->propbit);
- return 1;
- }
+ if (hi->application != HID_DG_TOUCHPAD)
+ return -1;
+
+ if (!haptic->auto_trigger_report || !haptic->manual_trigger_report)
+ return 0;
+
+ __set_bit(INPUT_PROP_PRESSUREPAD, hi->input->propbit);
+
+ error = hid_haptic_init(hdev, haptic, hi->input);
+ if (error) {
+ dev_warn(&hdev->dev, "Cannot allocate haptic for %s\n",
+ hdev->name);
return 0;
}
- return -1;
+
+ return 1;
}
EXPORT_SYMBOL_GPL(hid_haptic_input_configured);
@@ -401,11 +409,9 @@ static void hid_haptic_destroy(struct ff_device *ff)
}
int hid_haptic_init(struct hid_device *hdev,
- struct hid_haptic_device **haptic_ptr)
+ struct hid_haptic_device *haptic,
+ struct input_dev *dev)
{
- struct hid_haptic_device *haptic = *haptic_ptr;
- struct input_dev *dev = NULL;
- struct hid_input *hidinput;
struct ff_device *ff;
int ret = 0, r;
struct ff_haptic_effect stop_effect = {
@@ -447,19 +453,6 @@ int hid_haptic_init(struct hid_device *hdev,
for (r = 0; r < haptic->auto_trigger_report->maxfield; r++)
parse_auto_trigger_field(haptic, haptic->auto_trigger_report->field[r]);
- list_for_each_entry(hidinput, &hdev->inputs, list) {
- if (hidinput->application == HID_DG_TOUCHPAD) {
- dev = hidinput->input;
- break;
- }
- }
-
- if (!dev) {
- dev_err(&hdev->dev, "Failed to find the input device\n");
- ret = -ENODEV;
- goto duration_map;
- }
-
haptic->input_dev = dev;
haptic->manual_trigger_report_len =
hid_report_len(haptic->manual_trigger_report);
@@ -535,10 +528,6 @@ int hid_haptic_init(struct hid_device *hdev,
input_free:
input_ff_destroy(dev);
- /* Do not let double free happen, input_ff_destroy will call
- * hid_haptic_destroy.
- */
- *haptic_ptr = NULL;
/* Restore dev flush and event */
dev->flush = flush;
dev->event = event;
diff --git a/drivers/hid/hid-haptic.h b/drivers/hid/hid-haptic.h
index c6539ac04c1d..6332991a7844 100644
--- a/drivers/hid/hid-haptic.h
+++ b/drivers/hid/hid-haptic.h
@@ -69,7 +69,8 @@ int hid_haptic_input_mapping(struct hid_device *hdev,
int hid_haptic_input_configured(struct hid_device *hdev,
struct hid_haptic_device *haptic,
struct hid_input *hi);
-int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device **haptic_ptr);
+int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic,
+ struct input_dev *dev);
void hid_haptic_handle_press_release(struct hid_haptic_device *haptic);
void hid_haptic_pressure_reset(struct hid_haptic_device *haptic);
void hid_haptic_pressure_increase(struct hid_haptic_device *haptic,
@@ -107,7 +108,8 @@ static inline
void hid_haptic_reset(struct hid_device *hdev, struct hid_haptic_device *haptic)
{}
static inline
-int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device **haptic_ptr)
+int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic,
+ struct input_dev *dev)
{
return 0;
}
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index edb37b4c867e..15218e92aaa4 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -2189,16 +2189,8 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL);
- if (td->is_haptic_touchpad) {
- if (hid_haptic_init(hdev, &td->haptic)) {
- dev_warn(&hdev->dev, "Cannot allocate haptic for %s\n",
- hdev->name);
- td->is_haptic_touchpad = false;
- devm_kfree(&hdev->dev, td->haptic);
- }
- } else {
+ if (!td->is_haptic_touchpad)
devm_kfree(&hdev->dev, td->haptic);
- }
return 0;
}
--
2.55.0.629.g250fe7f194-goog
prev parent reply other threads:[~2026-08-03 18:47 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 ` [PATCH 13/21] HID: microsoft: move FF initialization to .input_configured() Dmitry Torokhov
2026-08-03 18:46 ` [PATCH 14/21] HID: pantherlord: " 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 ` Dmitry Torokhov [this message]
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-21-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