[PATCH] watchdog: ixp4xx: fix reference leak on platform_device_register() failure

Linus Walleij linusw at kernel.org
Sun Apr 19 13:22:34 PDT 2026


Hi Guangshuo,

thanks for your patch!

On Mon, Apr 13, 2026 at 5:47 PM Guangshuo Li <lgs201920130244 at gmail.com> wrote:

> ixp4xx_timer_probe() directly returns the result of
> platform_device_register(&ixp4xx_watchdog_device). When registration
> fails, the embedded struct device in ixp4xx_watchdog_device has already
> been initialized by device_initialize(), but the failure path does not
> drop the device reference, leading to a reference leak.
(...)

> -       return platform_device_register(&ixp4xx_watchdog_device);
> +       ret = platform_device_register(&ixp4xx_watchdog_device);
> +       if (ret)
> +               platform_device_put(&ixp4xx_watchdog_device);

If the problem in the description is indeed there, it seems the bug
is inside platform_device_register(), surely a function returning an
error code is supposed to clean up any resources it takes before
returning an error. It seems wrong to try to fix this in all the
consumers.

Yours,
Linus Walleij



More information about the linux-arm-kernel mailing list