HID: thrustmaster: Switch to kmemdup() when allocate change_request
authorYang Yingliang <yangyingliang@huawei.com>
Tue, 11 May 2021 11:30:33 +0000 (19:30 +0800)
committerJiri Kosina <jkosina@suse.cz>
Fri, 25 Jun 2021 12:11:01 +0000 (14:11 +0200)
Use kmemdup() helper instead of open-coding to
simplify the code when allocate change_request.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-thrustmaster.c

index f643b1cb112d591dbf2f9f0bfdf232760a75698c..cdc7d82ae9eda9a95e881e0d0fb04fce52d79f89 100644 (file)
@@ -311,12 +311,13 @@ static int thrustmaster_probe(struct hid_device *hdev, const struct hid_device_i
                goto error4;
        }
 
-       tm_wheel->change_request = kzalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
+       tm_wheel->change_request = kmemdup(&change_request,
+                                          sizeof(struct usb_ctrlrequest),
+                                          GFP_KERNEL);
        if (!tm_wheel->change_request) {
                ret = -ENOMEM;
                goto error5;
        }
-       memcpy(tm_wheel->change_request, &change_request, sizeof(struct usb_ctrlrequest));
 
        tm_wheel->usb_dev = interface_to_usbdev(to_usb_interface(hdev->dev.parent));
        hid_set_drvdata(hdev, tm_wheel);