[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250917045026.601848-1-masami256@gmail.com>
Date: Wed, 17 Sep 2025 13:50:26 +0900
From: Masami Ichikawa <masami256@...il.com>
To: jikos@...nel.org,
bentiss@...nel.org
Cc: minbell.kim@...sung.com,
linux-input@...r.kernel.org,
linux-kernel@...r.kernel.org,
Masami Ichikawa <masami256@...il.com>
Subject: [PATCH] HID: hid-ntrig: Fix potential memory leak in ntrig_report_version()
The kmalloc() was called before checking hid_is_usb(hdev). If hid_is_usb()
returned false, the function would return early and leak the allocated
memory.
It is safe to move the kmalloc() call after the hid_is_usb() check to avoid
unnecessary allocation and potential memory leak.
Fixes: 185c926283da ("HID: hid-ntrig: fix unable to handle page fault in ntrig_report_version()")
Signed-off-by: Masami Ichikawa <masami256@...il.com>
---
drivers/hid/hid-ntrig.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index 0f76e241e0af..52e8e7fe9681 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -142,11 +142,12 @@ 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 = NULL;
if (!hid_is_usb(hdev))
return;
+ data = kmalloc(8, GFP_KERNEL);
if (!data)
goto err_free;
--
2.51.0
Powered by blists - more mailing lists