HID: cp2112: destroy mutex on driver detach
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 23 Apr 2025 08:55:39 +0000 (10:55 +0200)
committerJiri Kosina <jkosina@suse.com>
Thu, 24 Apr 2025 10:07:55 +0000 (12:07 +0200)
Use the devres variant of mutex_init() in order to free resources
allocated with mutex debugging enabled.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
drivers/hid/hid-cp2112.c

index f4c8d981aa0a861ad3a06949c0f3a1a90d3b4f52..a001b9acd2d4a28a980205edf8efecdb1433936d 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/hidraw.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/nls.h>
 #include <linux/string_choices.h>
 #include <linux/usb/ch9.h>
@@ -1205,7 +1206,11 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
        if (!dev->in_out_buffer)
                return -ENOMEM;
 
-       mutex_init(&dev->lock);
+       ret = devm_mutex_init(&hdev->dev, &dev->lock);
+       if (ret) {
+               hid_err(hdev, "mutex init failed\n");
+               return ret;
+       }
 
        ret = hid_parse(hdev);
        if (ret) {