[PATCH] gpio: omap: fix reference leak on platform_device_register() failure
From: Guangshuo Li
Date: Mon Apr 13 2026 - 12:20:20 EST
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