[PATCH] platform/chrome: cros_ec_lpc: fix reference leak on failed device registration

From: Guangshuo Li

Date: Wed Apr 15 2026 - 13:59:00 EST


When platform_device_register() fails in cros_ec_lpc_init(), the
embedded struct device in cros_ec_lpc_device has already been
initialized by device_initialize(), but the failure path only reports
the error and unregisters the platform driver without dropping the
device reference for the current platform device:

cros_ec_lpc_init()
-> platform_device_register(&cros_ec_lpc_device)
-> device_initialize(&cros_ec_lpc_device.dev)
-> setup_pdev_dma_masks(&cros_ec_lpc_device)
-> platform_device_add(&cros_ec_lpc_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.

Fixes: 5f454bdf63536 ("platform/chrome: cros_ec_lpc: Register the driver if ACPI entry is missing.")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
drivers/platform/chrome/cros_ec_lpc.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c
index 78cfff80cdea..cb3ff76d29e9 100644
--- a/drivers/platform/chrome/cros_ec_lpc.c
+++ b/drivers/platform/chrome/cros_ec_lpc.c
@@ -892,6 +892,7 @@ static int __init cros_ec_lpc_init(void)
ret = platform_device_register(&cros_ec_lpc_device);
if (ret) {
pr_err(DRV_NAME ": can't register device: %d\n", ret);
+ platform_device_put(&cros_ec_lpc_device);
platform_driver_unregister(&cros_ec_lpc_driver);
}
}
--
2.43.0