[PATCH v2 31/33] HID: logitech-hidpp: manage send_mutex with devm_mutex_init()

From: Dmitry Torokhov

Date: Wed Nov 11 2026 - 02:02:42 EST


Manually initializing and destroying the HID++ command mutex in probe
and remove destroys the mutex before devres tears down managed child
resources such as the delayed input device and battery power supply.
Switching to devm_mutex_init() eliminates manual teardown boilerplate
while keeping the mutex valid throughout child device teardown.

Initialize the command mutex with devm_mutex_init() during probe,
returning early on allocation failure, and drop manual mutex
destruction from the error path and device removal handler.

Tested-by: Gideon Heinz <gideonheinz02@xxxxxxxxx>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/hid/hid-logitech-hidpp.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index b6c7a951cc94..be3c2649b0e3 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -4631,9 +4631,12 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
INIT_WORK(&hidpp->work, hidpp_connect_event);
disable_work(&hidpp->work);
INIT_WORK(&hidpp->reset_hi_res_work, hidpp_reset_hi_res_handler);
- mutex_init(&hidpp->send_mutex);
init_waitqueue_head(&hidpp->wait);

+ ret = devm_mutex_init(&hdev->dev, &hidpp->send_mutex);
+ if (ret)
+ return ret;
+
/* indicates we are handling the battery properties in the kernel */
ret = sysfs_create_group(&hdev->dev.kobj, &ps_attribute_group);
if (ret)
@@ -4710,7 +4713,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
hid_hw_stop(hdev);
hid_hw_start_fail:
sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
- mutex_destroy(&hidpp->send_mutex);
return ret;
}

@@ -4737,7 +4739,6 @@ static void hidpp_remove(struct hid_device *hdev)
hid_device_io_stop(hdev);

hid_hw_stop(hdev);
- mutex_destroy(&hidpp->send_mutex);
}

#define LDJ_DEVICE(product) \

--
2.56.0.542.g3ef89b7020-goog