[PATCH v2 22/33] HID: logitech-hidpp: shut down G920 force feedback on input unregister
From: Dmitry Torokhov
Date: Wed Nov 11 2026 - 02:09:42 EST
Force-feedback teardown currently runs only in the force-feedback
destroy callback, which is deferred until the last open event handle
is closed. If userspace holds an open handle across USB disconnect or
driver unbind, device removal frees driver state and destroys the
command mutex while queued force-feedback work is still active, causing
use-after-free errors.
Move workqueue teardown into the force-feedback stop callback so input
unregistration drains queued work while driver and HID state are still
alive. Keep calling stop from destroy as a safety net for registration
failures, guarded so repeated teardown is a safe no-op.
Fixes: 08c453f6d073 ("HID: logitech-hidpp: do all FF cleanup in hidpp_ff_destroy()")
Tested-by: Gideon Heinz <gideonheinz02@xxxxxxxxx>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/hid/hid-logitech-hidpp.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index f7fefff0aed4..ceaa57af6eab 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -2795,14 +2795,32 @@ static const struct attribute_group *hidpp_dev_groups[] = {
NULL
};
-static void hidpp_ff_destroy(struct ff_device *ff)
+static void hidpp_ff_stop(struct ff_device *ff)
{
struct hidpp_ff_private_data *data = ff->private;
- struct hidpp_device *hidpp = data->hidpp;
+ struct hidpp_device *hidpp;
+
+ hidpp = data->hidpp;
+ if (!hidpp)
+ return;
hid_info(hidpp->hid_dev, "Unloading HID++ force feedback.\n");
destroy_workqueue(data->wq);
+
+ data->wq = NULL;
+ data->hidpp = NULL;
+}
+
+static void hidpp_ff_destroy(struct ff_device *ff)
+{
+ /*
+ * Workqueue teardown normally runs in ff->stop() when the input device
+ * is unregistered. Still call it here as a safety net for error paths
+ * before registration completes; once stopped, it becomes a safe no-op
+ * that never touches freed driver data.
+ */
+ hidpp_ff_stop(ff);
}
static int g920_input_open(struct input_dev *dev)
@@ -2881,6 +2899,7 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, struct input_dev *dev)
ff->playback = hidpp_ff_playback;
ff->set_gain = hidpp_ff_set_gain;
ff->set_autocenter = hidpp_ff_set_autocenter;
+ ff->stop = hidpp_ff_stop;
ff->destroy = hidpp_ff_destroy;
dev->open = g920_input_open;
--
2.56.0.542.g3ef89b7020-goog