Re: [PATCH] gpio: omap: fix reference leak on platform_device_register() failure
From: Guangshuo Li
Date: Fri Apr 24 2026 - 04:10:36 EST
Hi,
Please disregard this patch.
On Tue, 14 Apr 2026 at 00:08, Guangshuo Li <lgs201920130244@xxxxxxxxx> wrote:
>
> omap_mpuio_init() ignores the return value of
> platform_device_register(&omap_mpuio_device).
>
> The call flow is:
>
> omap_mpuio_init()
> -> platform_device_register(&omap_mpuio_device)
> -> device_initialize(&omap_mpuio_device.dev)
> -> platform_device_add(&omap_mpuio_device)
>
> If platform_device_add() fails, omap_mpuio_init() continues without
> dropping the device reference acquired by device_initialize(), leading
> to a reference leak.
>
> The issue was identified by a static analysis tool I developed and
> confirmed by manual review. Fix this by calling platform_device_put()
> when platform_device_register() fails.
>
> Fixes: 730e5ebff40c8 ("gpio: omap: do not register driver in probe()")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
> ---
> drivers/gpio/gpio-omap.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
> index e39723b5901b..841bef431c22 100644
> --- a/drivers/gpio/gpio-omap.c
> +++ b/drivers/gpio/gpio-omap.c
> @@ -800,11 +800,15 @@ static struct platform_device omap_mpuio_device = {
> static inline void omap_mpuio_init(struct gpio_bank *bank)
> {
> static bool registered;
> + int ret;
>
> platform_set_drvdata(&omap_mpuio_device, bank);
> if (!registered) {
> - (void)platform_device_register(&omap_mpuio_device);
> - registered = true;
> + ret = platform_device_register(&omap_mpuio_device);
> + if (ret)
> + platform_device_put(&omap_mpuio_device);
> + else
> + registered = true;
> }
> }
>
> --
> 2.43.0
>
After re-checking it, omap_mpuio_device is a static platform_device and
it does not provide a dev.release callback. Therefore calling
platform_device_put() on the platform_device_register() failure path is
not appropriate here and can trigger the missing release callback warning.
This falls into the same static platform_device pattern pointed out in
the other reviews, so I will drop this patch.
Sorry for the noise.
Best regards,
Guangshuo Li