[PATCH] platform/chrome: fix reference leak on failed device registration
From: Guangshuo Li
Date: Wed Apr 15 2026 - 13:51:15 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
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