Message ID | 20250401094853.24143-1-bsdhenrymartin@gmail.com (mailing list archive) |
---|---|
State | New |
Delegated to: | Jiri Kosina |
Headers | show |
Series | [v3] HID: uclogic: Add NULL check in uclogic_input_configured() | expand |
> devm_kasprintf() return NULL if memory allocation fails. Currently, … call? failed? > Add NULL check after devm_kasprintf() to prevent this issue. Do you propose to improve this function implementation a bit more? … > --- > V2 -> V3: Kept the original switch structure, only optimized the outer > conditional checks while maintaining safety requirements. > V1 -> V2: Simplify the handing of the condition "suffix" with if/else. * Under which circumstances will you begin to care more to offer such adjustments in separate update steps? https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.14#n81 * Can another tag become more helpful? https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.14#n598 Can an other control flow variant be a bit nicer finally? if (suffix) { … } else { … } Regards, Markus
diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c index d8008933c052..321c43fb06ae 100644 --- a/drivers/hid/hid-uclogic-core.c +++ b/drivers/hid/hid-uclogic-core.c @@ -142,11 +142,12 @@ static int uclogic_input_configured(struct hid_device *hdev, suffix = "System Control"; break; } - } - - if (suffix) + } else { hi->input->name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "%s %s", hdev->name, suffix); + if (!hi->input->name) + return -ENOMEM; + } return 0; }
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> --- V2 -> V3: Kept the original switch structure, only optimized the outer conditional checks while maintaining safety requirements. V1 -> V2: Simplify the handing of the condition "suffix" with if/else. drivers/hid/hid-uclogic-core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)