Skip to content

Commit 53f731f

Browse files
masami256Jiri Kosina
authored andcommitted
HID: hid-ntrig: Prevent memory leak in ntrig_report_version()
Use a scope-based cleanup helper for the buffer allocated with kmalloc() in ntrig_report_version() to simplify the cleanup logic and prevent memory leaks (specifically the !hid_is_usb()-case one). [jkosina@suse.com: elaborate on the actual existing leak] Fixes: 185c926 ("HID: hid-ntrig: fix unable to handle page fault in ntrig_report_version()") Signed-off-by: Masami Ichikawa <masami256@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent 4d3a13a commit 53f731f

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

drivers/hid/hid-ntrig.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ static void ntrig_report_version(struct hid_device *hdev)
142142
int ret;
143143
char buf[20];
144144
struct usb_device *usb_dev = hid_to_usb_dev(hdev);
145-
unsigned char *data = kmalloc(8, GFP_KERNEL);
145+
unsigned char *data __free(kfree) = kmalloc(8, GFP_KERNEL);
146146

147147
if (!hid_is_usb(hdev))
148148
return;
149149

150150
if (!data)
151-
goto err_free;
151+
return;
152152

153153
ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
154154
USB_REQ_CLEAR_FEATURE,
@@ -163,9 +163,6 @@ static void ntrig_report_version(struct hid_device *hdev)
163163
hid_info(hdev, "Firmware version: %s (%02x%02x %02x%02x)\n",
164164
buf, data[2], data[3], data[4], data[5]);
165165
}
166-
167-
err_free:
168-
kfree(data);
169166
}
170167

171168
static ssize_t show_phys_width(struct device *dev,

0 commit comments

Comments
 (0)