[PATCH] HID: uclogic: Add NULL check in uclogic_input_configured

Henry Martin posted 1 patch 8 months, 3 weeks ago
There is a newer version of this series
drivers/hid/hid-uclogic-core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH] HID: uclogic: Add NULL check in uclogic_input_configured
Posted by Henry Martin 8 months, 3 weeks ago
devm_kasprintf() can return a NULL pointer on failure, but this
returned value in uclogic_input_configured is not checked.

Add NULL check in uclogic_input_configured, to handle kernel NULL
pointer dereference error.

Fixes: dd613a4e45f8d("HID: uclogic: Correct devm device reference for hidinput input_dev name")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 drivers/hid/hid-uclogic-core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c
index d8008933c052..f8708a1ec7cc 100644
--- a/drivers/hid/hid-uclogic-core.c
+++ b/drivers/hid/hid-uclogic-core.c
@@ -144,9 +144,12 @@ static int uclogic_input_configured(struct hid_device *hdev,
 		}
 	}
 
-	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
Re: [PATCH] HID: uclogic: Add NULL check in uclogic_input_configured
Posted by Markus Elfring 8 months, 3 weeks ago
…
> Add NULL check in uclogic_input_configured, to handle kernel NULL
> pointer dereference error.

Do you complete the error/exception handling also with the statement “return -ENOMEM;”?


By the way:
I suggest to simplify the handling of the condition “suffix”
with if/else branches a bit.

Regards,
Markus