* [PATCH v2] HID: hid-ntrig: Prevent memory leak in ntrig_report_version()
@ 2025-09-21 5:31 Masami Ichikawa
2025-10-31 8:59 ` Jiri Kosina
0 siblings, 1 reply; 2+ messages in thread
From: Masami Ichikawa @ 2025-09-21 5:31 UTC (permalink / raw)
To: jikos, bentiss; +Cc: minbell.kim, linux-input, linux-kernel, Masami Ichikawa
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.
Fixes: 185c926283da ("HID: hid-ntrig: fix unable to handle page fault in ntrig_report_version()")
Signed-off-by: Masami Ichikawa <masami256@gmail.com>
---
Changes from v1:
- Rewrite patch title
- Use scope-based cleanup to drop goto-based error path
---
drivers/hid/hid-ntrig.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index 0f76e241e0af..a7f10c45f62b 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -142,13 +142,13 @@ static void ntrig_report_version(struct hid_device *hdev)
int ret;
char buf[20];
struct usb_device *usb_dev = hid_to_usb_dev(hdev);
- unsigned char *data = kmalloc(8, GFP_KERNEL);
+ unsigned char *data __free(kfree) = kmalloc(8, GFP_KERNEL);
if (!hid_is_usb(hdev))
return;
if (!data)
- goto err_free;
+ return;
ret = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
USB_REQ_CLEAR_FEATURE,
@@ -163,9 +163,6 @@ static void ntrig_report_version(struct hid_device *hdev)
hid_info(hdev, "Firmware version: %s (%02x%02x %02x%02x)\n",
buf, data[2], data[3], data[4], data[5]);
}
-
-err_free:
- kfree(data);
}
static ssize_t show_phys_width(struct device *dev,
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] HID: hid-ntrig: Prevent memory leak in ntrig_report_version()
2025-09-21 5:31 [PATCH v2] HID: hid-ntrig: Prevent memory leak in ntrig_report_version() Masami Ichikawa
@ 2025-10-31 8:59 ` Jiri Kosina
0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2025-10-31 8:59 UTC (permalink / raw)
To: Masami Ichikawa; +Cc: bentiss, minbell.kim, linux-input, linux-kernel
On Sun, 21 Sep 2025, Masami Ichikawa wrote:
> 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.
>
> Fixes: 185c926283da ("HID: hid-ntrig: fix unable to handle page fault in ntrig_report_version()")
> Signed-off-by: Masami Ichikawa <masami256@gmail.com>
I have added an explicit reference to the real actual leak being fixed
into the changelog, and applied, thanks.
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-31 8:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-21 5:31 [PATCH v2] HID: hid-ntrig: Prevent memory leak in ntrig_report_version() Masami Ichikawa
2025-10-31 8:59 ` Jiri Kosina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox