Skip to contentSkip to conversation

coreboot_table: skip failing entries instead of aborting populate

PATCH Superseded Titouan Ameline de Cadeville 3 participants 3 messages Apr 30

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 coreboot_table: skip failing entries instead of aborting populate

coreboot_table_populate() registers devices one by one. If device_register() fails for one entry, the current code returns immediately, leaving previously registered devices orphaned on the coreboot bus with no cleanup path.

Since coreboot table entries are independent of each other, a failure on one entry should not prevent the others from being registered. This mirrors the strategy used by of_platform_populate(), which skips individual failures rather than aborting.

Log a warning and continue the loop on device_register() failure.

---
v2: continue the loop on failure instead of unregistering all devices
(suggested by Julius Werner, with reference to of_platform_populate() from Brian Norris)

 drivers/firmware/google/coreboot_table.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/firmware/google/coreboot_table.c +2 -1
index c769631ea15d..82be21434be4 100644
@@ -150,8 +150,9 @@ static int coreboot_table_populate(struct device *dev, void *ptr)
 
 		ret = device_register(&device->dev);
 		if (ret) {
+			dev_warn(dev, "failed to register coreboot device: %d\n", ret);
 			put_device(&device->dev);
-			return ret;
+			continue;
 		}
 
 		ptr_entry += entry->size;
Signature · 1 line
2.44.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines

coreboot_table_populate() registers devices one by one. If device_register() fails for one entry, the current code returns immediately, leaving previously registered devices orphaned on the coreboot bus with no cleanup path.

Quoted 8 lines

Since coreboot table entries are independent of each other, a failure on one entry should not prevent the others from being registered. This mirrors the strategy used by of_platform_populate(), which skips individual failures rather than aborting.

Log a warning and continue the loop on device_register() failure.

#2 lore raw
In reply to Titouan Ameline de Cadeville
Quoted 26 lines · Titouan Ameline de Cadeville

coreboot_table_populate() registers devices one by one. If device_register() fails for one entry, the current code returns immediately, leaving previously registered devices orphaned on the coreboot bus with no cleanup path.

Since coreboot table entries are independent of each other, a failure on one entry should not prevent the others from being registered. This mirrors the strategy used by of_platform_populate(), which skips individual failures rather than aborting.

Log a warning and continue the loop on device_register() failure.

---
v2: continue the loop on failure instead of unregistering all devices
(suggested by Julius Werner, with reference to of_platform_populate() from Brian Norris)

 drivers/firmware/google/coreboot_table.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/firmware/google/coreboot_table.c +0 -0
index c769631ea15d..82be21434be4 100644

drivers/firmware/google/coreboot_table.c static int coreboot_table_populate(struct device *dev, void *ptr) · line 158

Quoted 10 lines
drivers/firmware/google/coreboot_table.c +2 -1
@@ -150,8 +150,9 @@ static int coreboot_table_populate(struct device *dev, void *ptr)
 
 		ret = device_register(&device->dev);
 		if (ret) {
+			dev_warn(dev, "failed to register coreboot device: %d\n", ret);
 			put_device(&device->dev);
-			return ret;
+			continue;
 		}
 
 		ptr_entry += entry->size;

Isn't it important to still increment ptr_entry on failure/continue? Otherwise, you may re-populate a new device with the same contents, and you may not actually register all devices. (You'll be off-by-1, at least.)

To fix this, you could either drop the 'continue' (let it fall through) or else move this line up.

Brian

Quoted 3 lines
Signature · 1 line
2.44.2