Re: [PATCH] regulator: wm8400: fix reference leak on failed device registration
From: Mark Brown
Date: Mon Apr 20 2026 - 13:38:29 EST
On Thu, Apr 16, 2026 at 02:12:28AM +0800, Guangshuo Li wrote:
> When platform_device_register() fails in wm8400_register_regulator(),
> the embedded struct device in wm8400->regulators[reg] has already been
> initialized by device_initialize(), but the failure path returns the
> error without dropping the device reference for the current platform
> device:
> - return platform_device_register(&wm8400->regulators[reg]);
> + ret = platform_device_register(&wm8400->regulators[reg]);
> + if (ret)
> + platform_device_put(&wm8400->regulators[reg]);
Note that the device is embedded in wm8400 so we don't want to free it,
and we don't have a release() callback anyway. The whole lifecycle is
messed up here, the subdevices should probably be dynamically allocated.
Attachment:
signature.asc
Description: PGP signature