* [PATCH] fbdev: omapfb: fix reference leak on failed device registration
@ 2026-04-15 19:17 Guangshuo Li
2026-04-22 14:30 ` Helge Deller
0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-04-15 19:17 UTC (permalink / raw)
To: Helge Deller, Thomas Zimmermann, Kees Cook, Guangshuo Li,
Dan Carpenter, Tomi Valkeinen, linux-fbdev, linux-omap, dri-devel,
linux-kernel
Cc: stable
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.
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@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
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;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] fbdev: omapfb: fix reference leak on failed device registration
2026-04-15 19:17 [PATCH] fbdev: omapfb: fix reference leak on failed device registration Guangshuo Li
@ 2026-04-22 14:30 ` Helge Deller
0 siblings, 0 replies; 2+ messages in thread
From: Helge Deller @ 2026-04-22 14:30 UTC (permalink / raw)
To: Guangshuo Li, Thomas Zimmermann, Kees Cook, Dan Carpenter,
Tomi Valkeinen, linux-fbdev, linux-omap, dri-devel, linux-kernel
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@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> 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;
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-22 14:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 19:17 [PATCH] fbdev: omapfb: fix reference leak on failed device registration Guangshuo Li
2026-04-22 14:30 ` Helge Deller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox