Re: [PATCH v2] clk: eyeq: fix memory leak in eqc_auxdev_create() error path
From: Brian Masney
Date: Mon Apr 13 2026 - 12:53:54 EST
Hi Guangshuo,
On Sun, Apr 12, 2026 at 08:42:46PM +0800, Guangshuo Li wrote:
> eqc_auxdev_create() allocates an auxiliary_device with kzalloc() before
> calling auxiliary_device_init().
>
> When auxiliary_device_init() returns an error, the function exits
> without freeing adev. Since the release callback is only expected to
> handle cleanup after successful initialization, adev should be freed
> explicitly in this path.
>
> Add the missing kfree(adev) before returning from the
> auxiliary_device_init() error path.
>
> Fixes: 25d904946a0b ("clk: eyeq: add driver")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
> ---
> drivers/clk/clk-eyeq.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/clk-eyeq.c b/drivers/clk/clk-eyeq.c
> index ea1c3d78e7cd..a48ecec4c9a5 100644
> --- a/drivers/clk/clk-eyeq.c
> +++ b/drivers/clk/clk-eyeq.c
> @@ -346,8 +346,10 @@ static int eqc_auxdev_create(struct device *dev, void __iomem *base,
> adev->id = id;
>
> ret = auxiliary_device_init(adev);
> - if (ret)
> + if (ret) {
> + kfree(adev);
> return ret;
> + }
>
> ret = auxiliary_device_add(adev);
> if (ret)
There is a leak in the error path here as well. I think this code
should be converted to devm_kzalloc().
There is no devm_kzalloc_obj() yet, however according to [1] that should
be coming soon.
[1] https://lore.kernel.org/lkml/20260330154108.GA3389518@xxxxxxxxxxxxxxxxxxxxxxxxxx/
Brian