[PATCH] firmware: google: fix orphaned devices on partial populate failure
From: Titouan Ameline de Cadeville
Date: Sun Apr 26 2026 - 18:02:22 EST
coreboot_table_populate() registers devices one by one. If
device_register() fails mid-loop, the function returns an error to
coreboot_table_probe(), which returns it to the platform driver core.
The platform driver core does not call remove() on probe failure, so
devices registered before the failure are left orphaned on the coreboot
bus with no cleanup path.
Call bus_for_each_dev() to unregister all devices when populate fails.
Signed-off-by: Titouan Ameline de Cadeville <titouan.ameline@xxxxxxxxx>
---
drivers/firmware/google/coreboot_table.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/firmware/google/coreboot_table.c b/drivers/firmware/google/coreboot_table.c
index 233939e548b4..2ebf1497f60c 100644
--- a/drivers/firmware/google/coreboot_table.c
+++ b/drivers/firmware/google/coreboot_table.c
@@ -167,6 +167,12 @@ static int coreboot_table_populate(struct device *dev, void *ptr, resource_size_
return 0;
}
+static int __cb_dev_unregister(struct device *dev, void *dummy)
+{
+ device_unregister(dev);
+ return 0;
+}
+
static int coreboot_table_probe(struct platform_device *pdev)
{
resource_size_t len;
@@ -203,17 +209,14 @@ static int coreboot_table_probe(struct platform_device *pdev)
ret = coreboot_table_populate(dev, ptr, len);
+ if (ret)
+ bus_for_each_dev(&coreboot_bus_type, NULL, NULL,
+ __cb_dev_unregister);
memunmap(ptr);
return ret;
}
-static int __cb_dev_unregister(struct device *dev, void *dummy)
-{
- device_unregister(dev);
- return 0;
-}
-
static void coreboot_table_remove(struct platform_device *pdev)
{
bus_for_each_dev(&coreboot_bus_type, NULL, NULL, __cb_dev_unregister);
--
2.44.2