From: Masami Ichikawa <masami256@gmail.com>
To: jikos@kernel.org, bentiss@kernel.org
Cc: minbell.kim@samsung.com, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org,
Masami Ichikawa <masami256@gmail.com>
Subject: [PATCH] HID: hid-ntrig: Fix potential memory leak in ntrig_report_version()
Date: Wed, 17 Sep 2025 13:50:26 +0900 [thread overview]
Message-ID: <20250917045026.601848-1-masami256@gmail.com> (raw)
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@gmail.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
next reply other threads:[~2025-09-17 4:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-17 4:50 Masami Ichikawa [this message]
2025-09-17 7:46 ` [PATCH] HID: hid-ntrig: Fix potential memory leak in ntrig_report_version() Markus Elfring
2025-09-18 1:46 ` Masami Ichikawa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250917045026.601848-1-masami256@gmail.com \
--to=masami256@gmail.com \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=minbell.kim@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).