public inbox for linux-fbdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fbdev: dnfb: fix reference leak on failed device registration
@ 2026-04-15 19:07 Guangshuo Li
  0 siblings, 0 replies; only message in thread
From: Guangshuo Li @ 2026-04-15 19:07 UTC (permalink / raw)
  To: Helge Deller, Guangshuo Li, linux-fbdev, dri-devel, linux-kernel; +Cc: stable

When platform_device_register() fails in dnfb_init(), the embedded
struct device in dnfb_device has already been initialized by
device_initialize(), but the failure path only unregisters the platform
driver and does not drop the device reference for the current platform
device:

  dnfb_init()
    -> platform_device_register(&dnfb_device)
       -> device_initialize(&dnfb_device.dev)
       -> setup_pdev_dma_masks(&dnfb_device)
       -> platform_device_add(&dnfb_device)

This leads to a reference leak when platform_device_register() fails.
Fix this by calling platform_device_put() before unregistering the
platform driver.

The issue was identified by a static analysis tool I developed and
confirmed by manual review.

Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/video/fbdev/dnfb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/dnfb.c b/drivers/video/fbdev/dnfb.c
index c4d24540d9ef..72a9c47418f8 100644
--- a/drivers/video/fbdev/dnfb.c
+++ b/drivers/video/fbdev/dnfb.c
@@ -296,8 +296,10 @@ static int __init dnfb_init(void)
 
 	if (!ret) {
 		ret = platform_device_register(&dnfb_device);
-		if (ret)
+		if (ret) {
+			platform_device_put(&dnfb_device);
 			platform_driver_unregister(&dnfb_driver);
+		}
 	}
 	return ret;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-04-15 19:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 19:07 [PATCH] fbdev: dnfb: fix reference leak on failed device registration Guangshuo Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox