public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/chrome: fix reference leak on failed device registration
@ 2026-04-15 17:50 Guangshuo Li
  2026-04-15 21:47 ` Olof Johansson
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Guangshuo Li @ 2026-04-15 17:50 UTC (permalink / raw)
  To: Benson Leung, Tzung-Bi Shih, Olof Johansson, chrome-platform,
	linux-kernel
  Cc: Guangshuo Li, stable

When platform_device_register() fails in chromeos_pstore_init(), the
embedded struct device in chromeos_ramoops has already been initialized
by device_initialize(), but the failure path returns the error without
dropping the device reference for the current platform device:

  chromeos_pstore_init()
    -> platform_device_register(&chromeos_ramoops)
       -> device_initialize(&chromeos_ramoops.dev)
       -> setup_pdev_dma_masks(&chromeos_ramoops)
       -> platform_device_add(&chromeos_ramoops)

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: 9742e127cd0dd ("platform/chrome: Add pstore platform_device")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/platform/chrome/chromeos_pstore.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/chrome/chromeos_pstore.c b/drivers/platform/chrome/chromeos_pstore.c
index a6eed99507d4..9e6d14dbb1c2 100644
--- a/drivers/platform/chrome/chromeos_pstore.c
+++ b/drivers/platform/chrome/chromeos_pstore.c
@@ -127,8 +127,13 @@ static int __init chromeos_pstore_init(void)
 	/* First check ACPI for non-hardcoded values from firmware. */
 	acpi_dev_found = chromeos_check_acpi();
 
-	if (acpi_dev_found || dmi_check_system(chromeos_pstore_dmi_table))
-		return platform_device_register(&chromeos_ramoops);
+	if (acpi_dev_found || dmi_check_system(chromeos_pstore_dmi_table)) {
+		ret = platform_device_register(&chromeos_ramoops);
+		if (ret)
+			platform_device_put(&chromeos_ramoops);
+
+		return ret;
+	}
 
 	return -ENODEV;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-04-17  9:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 17:50 [PATCH] platform/chrome: fix reference leak on failed device registration Guangshuo Li
2026-04-15 21:47 ` Olof Johansson
2026-04-16  9:26   ` Guangshuo Li
2026-04-16 10:21     ` Guangshuo Li
2026-04-17  7:51 ` kernel test robot
2026-04-17  8:46 ` kernel test robot
2026-04-17  9:11   ` Guangshuo Li

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