Re: [PATCH v3] clk: starfive: jh7110: fix memory leak in jh7110_reset_controller_register() error path
From: Guangshuo Li
Date: Tue Apr 14 2026 - 07:44:54 EST
Hi Brian,
Thanks for reviewing.
On Tue, 14 Apr 2026 at 00:46, Brian Masney <bmasney@xxxxxxxxxx> wrote:
> There's actually another leak in the error path for
> auxiliary_device_add(). 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
>
I may be missing something, but I think the auxiliary_device_add() error
path is already handled here:
ret = auxiliary_device_add(adev);
if (ret) {
auxiliary_device_uninit(adev);
return ret;
}
The embedded auxiliary_device has:
adev->dev.release = jh7110_reset_adev_release;
and the release callback does:
static void jh7110_reset_adev_release(struct device *dev)
{
struct auxiliary_device *adev = to_auxiliary_dev(dev);
struct jh71x0_reset_adev *rdev = to_jh71x0_reset_adev(adev);
kfree(rdev);
}
So my understanding was that after a successful auxiliary_device_init(),
the auxiliary_device_add() failure path should be cleaned up through
auxiliary_device_uninit(), which would eventually call the release
callback and free rdev.
The leak I was trying to fix is only the auxiliary_device_init() failure
path, where the function returns directly before that cleanup mechanism is
available.
Please let me know if I overlooked something.
Thanks,
Guangshuo