[PATCH] HID: uclogic: Fix potential memory leak in error path

Abdun Nihaal posted 1 patch 3 months ago
drivers/hid/hid-uclogic-params.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] HID: uclogic: Fix potential memory leak in error path
Posted by Abdun Nihaal 3 months ago
In uclogic_params_ugee_v2_init_event_hooks(), the memory allocated for
event_hook is not freed in the next error path. Fix that by freeing it.

Fixes: a251d6576d2a ("HID: uclogic: Handle wireless device reconnection")
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
Compile tested only. Found using static analysis.

 drivers/hid/hid-uclogic-params.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-uclogic-params.c b/drivers/hid/hid-uclogic-params.c
index 59ea71299438..e28176d9d9c9 100644
--- a/drivers/hid/hid-uclogic-params.c
+++ b/drivers/hid/hid-uclogic-params.c
@@ -1372,8 +1372,10 @@ static int uclogic_params_ugee_v2_init_event_hooks(struct hid_device *hdev,
 	event_hook->hdev = hdev;
 	event_hook->size = ARRAY_SIZE(reconnect_event);
 	event_hook->event = kmemdup(reconnect_event, event_hook->size, GFP_KERNEL);
-	if (!event_hook->event)
+	if (!event_hook->event) {
+		kfree(event_hook);
 		return -ENOMEM;
+	}
 
 	list_add_tail(&event_hook->list, &p->event_hooks->list);
 
-- 
2.43.0
Re: [PATCH] HID: uclogic: Fix potential memory leak in error path
Posted by Jiri Kosina 2 months, 3 weeks ago
On Mon, 10 Nov 2025, Abdun Nihaal wrote:

> In uclogic_params_ugee_v2_init_event_hooks(), the memory allocated for
> event_hook is not freed in the next error path. Fix that by freeing it.
> 
> Fixes: a251d6576d2a ("HID: uclogic: Handle wireless device reconnection")
> Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs