[PATCH 11/18] HID: logitech-hidpp: shut down G920 force feedback on input unregister
From: Dmitry Torokhov
Date: Mon Nov 09 2026 - 01:12:35 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()")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/hid/hid-logitech-hidpp.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index ad3edd15cdd2..5169f3873257 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -2840,16 +2840,35 @@ 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 g920_data *g920 = hidpp->private_data;
+ struct hidpp_device *hidpp;
+ struct g920_data *g920;
+
+ hidpp = data->hidpp;
+ if (!hidpp)
+ return;
hid_info(hidpp->hid_dev, "Unloading HID++ force feedback.\n");
destroy_workqueue(data->wq);
+
+ g920 = hidpp->private_data;
g920->ff = NULL;
+ 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 void hidpp_ff_close(struct input_dev *dev)
@@ -2922,6 +2941,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->close = hidpp_ff_close;
--
2.56.0.506.g506a7eabc5-goog