[PATCH v3 2/2] HID: uclogic: fix desc_ptr leak in probe error path

From: Doruk Tan Ozturk

Date: Mon Jul 13 2026 - 18:00:07 EST


uclogic_probe() calls uclogic_params_get_desc(), which stores a
kmalloc-allocated replacement report descriptor into drvdata->desc_ptr.
If a later init step (hid_parse() or hid_hw_start()) fails, probe jumps
to the "failure" label, which only runs uclogic_params_cleanup() on
drvdata->params and returns. The device core does not call
uclogic_remove() when probe fails, so the kfree(drvdata->desc_ptr) that
uclogic_remove() normally performs never runs, leaking the descriptor.

drvdata itself is devm-allocated and freed automatically, but desc_ptr
is a plain kmalloc/krealloc buffer and must be freed explicitly. Free it
on the probe error path. The kfree is gated on params_initialized, under
which desc_ptr is either NULL (a no-op) or the allocated descriptor.

Found by 0sec (https://0sec.ai).

Fixes: 9614219e9310 ("HID: uclogic: Extract tablet parameter discovery into a module")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: 0sec
Signed-off-by: Doruk Tan Ozturk <doruk@xxxxxxx>
---
drivers/hid/hid-uclogic-core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c
index d74f98efa879..ad9914ed0c71 100644
--- a/drivers/hid/hid-uclogic-core.c
+++ b/drivers/hid/hid-uclogic-core.c
@@ -265,8 +265,10 @@ static int uclogic_probe(struct hid_device *hdev,
return 0;
failure:
/* Assume "remove" might not be called if "probe" failed */
- if (params_initialized)
+ if (params_initialized) {
+ kfree(drvdata->desc_ptr);
uclogic_params_cleanup(&drvdata->params);
+ }
/*
* If hid_hw_start() started I/O and then failed, raw_event may have
* armed the timer; shut it down so it cannot fire on the devm-freed
--
2.43.0