Re: [PATCH v2] media: radio-keene: fix memory leak in error path
From: Abdun Nihaal
Date: Wed Nov 26 2025 - 12:46:37 EST
On Wed, Nov 26, 2025 at 12:00:00PM +0530, ssrane_b23@xxxxxxxxxxxxx wrote:
> Fix a memory leak in usb_keene_probe() when v4l2_device_register()
> fails. The v4l2 control handler was initialized and controls were
> added, but if v4l2_device_register() failed, the handler was never
> freed, leaking the allocated memory for the handler buckets and
> control structures.
>
> Consolidate the error handling by adding an err_hdl label that
> ensures v4l2_ctrl_handler_free() is called for all error paths
> after the handler is initialized.
>
> ---
> v2:
> - Simplified fix: call v4l2_ctrl_handler_free() inline before goto
> instead of adding a new error label, avoiding unused label warning
> reported by Media CI.
v4l2_ctrl_handler_free() has to be called in the last error path also
(the one after the v4l2_device_register() call).
Your v1 patch was correct and also better because it avoided repeated
calls to v4l2_ctrl_handler_free() in different error paths.
To fix the unused label warning just use err_v4l2 itself instead of
introducing err_hdl, because both error path that goes to err_v4l2
needs to call v4l2_ctrl_handler_free() to fix the memory leak.
Regards,
Nihaal