public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Titouan Ameline de Cadeville <titouan.ameline@gmail.com>
To: tzungbi@kernel.org
Cc: briannorris@chromium.org, jwerner@chromium.org,
	chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org,
	Titouan Ameline de Cadeville <titouan.ameline@gmail.com>
Subject: [PATCH] firmware: google: fix orphaned devices on partial populate failure
Date: Mon, 27 Apr 2026 00:02:04 +0200	[thread overview]
Message-ID: <20260426220204.118399-1-titouan.ameline@gmail.com> (raw)

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@gmail.com>
---
 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


             reply	other threads:[~2026-04-26 22:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-26 22:02 Titouan Ameline de Cadeville [this message]
2026-04-27 19:03 ` [PATCH] firmware: google: fix orphaned devices on partial populate failure Julius Werner
2026-04-27 21:36   ` Titouan Ameline
2026-04-28 19:49     ` Julius Werner
2026-04-28 20:33       ` Brian Norris
2026-04-30  8:30         ` Titouan Ameline

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260426220204.118399-1-titouan.ameline@gmail.com \
    --to=titouan.ameline@gmail.com \
    --cc=briannorris@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=jwerner@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tzungbi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox