Re: [PATCH] fbdev: omapfb: fix reference leak on failed device registration
From: Helge Deller
Date: Wed Apr 22 2026 - 10:35:20 EST
Hello Guanghshuo,
On 4/15/26 21:17, Guangshuo Li wrote:
When platform_device_register() fails in omapfb_probe(), the embedded
struct device in omapdss_device has already been initialized by
device_initialize(), but the failure path only reports the error and
returns without dropping the device reference for the current platform
device:
omapfb_probe()
-> platform_device_register(&omapdss_device)
-> device_initialize(&omapdss_device.dev)
-> setup_pdev_dma_masks(&omapdss_device)
-> platform_device_add(&omapdss_device)
This leads to a reference leak when platform_device_register() fails.
Fix this by calling platform_device_put() before returning the error.
I see you submitted quite some patches, all about the same issue.
I did not yet fully checked if there is really a reference leak, but even if
it would be, I think it's wrong that all the callers in the whole Linux kernel source
would now need to use platform_device_put(). To me it then seems as if everyone got it wrong.
IMHO if platform_device_register() fails it should put the device itself before
returning.
Just looking at generic code, see platform_add_devices() in drivers/base/platform.c
which seem to have it wrong too then...
Helge
The issue was identified by a static analysis tool I developed and
confirmed by manual review.
Fixes: f778a12dd3320 ("OMAP: OMAPFB: fix clk_get for RFBI")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/video/fbdev/omap/omapfb_main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
index cafe859d6e5a..0d47a8aec5c5 100644
--- a/drivers/video/fbdev/omap/omapfb_main.c
+++ b/drivers/video/fbdev/omap/omapfb_main.c
@@ -1768,6 +1768,7 @@ static int omapfb_probe(struct platform_device *pdev)
r = platform_device_register(&omapdss_device);
if (r) {
dev_err(&pdev->dev, "can't register omapdss device\n");
+ platform_device_put(&omapdss_device);
return r;
}