From: Henry Martin <bsdhenrymartin@gmail.com>
To: jikos@kernel.org, bentiss@kernel.org
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Henry Martin <bsdhenrymartin@gmail.com>
Subject: [PATCH v2] HID: uclogic: Add NULL check in uclogic_input_configured
Date: Tue, 1 Apr 2025 14:31:57 +0800 [thread overview]
Message-ID: <20250401063157.19655-1-bsdhenrymartin@gmail.com> (raw)
devm_kasprintf() returns NULL when memory allocation fails. Currently,
uclogic_input_configured() does not check for this case, which results in a
NULL pointer dereference.
Add NULL check after devm_kasprintf() to prevent this issue.
Fixes: dd613a4e45f8 ("HID: uclogic: Correct devm device reference for hidinput input_dev name")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
V1 -> V2:
Simplify the handing of the condition "suffix" with if/else suggested by
Markus.
The current implementation (directly returning -ENOMEM) is reasonable because:
1. pen_input is just a cached pointer - no resources are allocated
2. evbit modification is a software-only configuration (hardware-independent)
3. No critical state needs rollback on memory allocation failure
drivers/hid/hid-uclogic-core.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c
index d8008933c052..83625ec6a55a 100644
--- a/drivers/hid/hid-uclogic-core.c
+++ b/drivers/hid/hid-uclogic-core.c
@@ -118,35 +118,29 @@ static int uclogic_input_configured(struct hid_device *hdev,
}
}
- if (!suffix) {
+ if (!suffix && hi->report->maxfield > 0) {
field = hi->report->field[0];
- switch (field->application) {
- case HID_GD_KEYBOARD:
+ if (field->application == HID_GD_KEYBOARD)
suffix = "Keyboard";
- break;
- case HID_GD_MOUSE:
+ else if (field->application == HID_GD_MOUSE)
suffix = "Mouse";
- break;
- case HID_GD_KEYPAD:
+ else if (field->application == HID_GD_KEYPAD)
suffix = "Pad";
- break;
- case HID_DG_PEN:
- case HID_DG_DIGITIZER:
+ else if (field->application == HID_DG_PEN || field->application == HID_DG_DIGITIZER)
suffix = "Pen";
- break;
- case HID_CP_CONSUMER_CONTROL:
+ else if (field->application == HID_CP_CONSUMER_CONTROL)
suffix = "Consumer Control";
- break;
- case HID_GD_SYSTEM_CONTROL:
+ else if (field->application == HID_GD_SYSTEM_CONTROL)
suffix = "System Control";
- break;
- }
}
- if (suffix)
+ if (suffix) {
hi->input->name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
"%s %s", hdev->name, suffix);
+ if (!hi->input->name)
+ return -ENOMEM;
+ }
return 0;
}
--
2.34.1
next reply other threads:[~2025-04-01 6:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-01 6:31 Henry Martin [this message]
2025-04-01 8:21 ` [PATCH v2] HID: uclogic: Add NULL check in uclogic_input_configured Markus Elfring
2025-04-01 9:48 ` [PATCH v3] HID: uclogic: Add NULL check in uclogic_input_configured() Henry Martin
2025-04-01 10:14 ` Markus Elfring
2025-04-24 10:12 ` Jiri Kosina
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=20250401063157.19655-1-bsdhenrymartin@gmail.com \
--to=bsdhenrymartin@gmail.com \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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).