Linux driver-core infrastructure
 help / color / mirror / Atom feed
* [PATCH v1] firmware_loader: Unwind initialization on sysfs failure
@ 2026-08-03  1:29 Yuho Choi
  0 siblings, 0 replies; only message in thread
From: Yuho Choi @ 2026-08-03  1:29 UTC (permalink / raw)
  To: mcgrof, russ.weight, dakr, gregkh, rafael, nixiaoming
  Cc: driver-core, linux-kernel, Yuho Choi

firmware_class_init() leaves the firmware PM operations and reboot
notifier registered when register_sysfs_loader() fails. In addition, the
sysfs loader can leave the firmware class registered if its sysctl setup
fails.

Unwind the reboot notifier and firmware PM operations when sysfs loader
registration fails. Make register_sysfs_loader() transactional by
unregistering the firmware class if its sysctl registration fails.

Fixes: 6bb9cf3aa3ed ("firmware: provide helpers for registering the syfs loader")
Fixes: 6aad36d421d8 ("firmware_loader: move firmware sysctl to its own files")
Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
---
 drivers/base/firmware_loader/main.c  | 8 +++++++-
 drivers/base/firmware_loader/sysfs.c | 7 ++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
index 24213a0ea831..c2f7825dfc4a 100644
--- a/drivers/base/firmware_loader/main.c
+++ b/drivers/base/firmware_loader/main.c
@@ -1727,8 +1727,14 @@ static int __init firmware_class_init(void)
 	if (ret)
 		goto out;
 
-	return register_sysfs_loader();
+	ret = register_sysfs_loader();
+	if (ret)
+		goto out_reboot;
+
+	return 0;
 
+out_reboot:
+	unregister_reboot_notifier(&fw_shutdown_nb);
 out:
 	unregister_fw_pm_ops();
 	return ret;
diff --git a/drivers/base/firmware_loader/sysfs.c b/drivers/base/firmware_loader/sysfs.c
index 29a10d2ad537..d9deb0804f55 100644
--- a/drivers/base/firmware_loader/sysfs.c
+++ b/drivers/base/firmware_loader/sysfs.c
@@ -117,7 +117,12 @@ int register_sysfs_loader(void)
 
 	if (ret != 0)
 		return ret;
-	return register_firmware_config_sysctl();
+
+	ret = register_firmware_config_sysctl();
+	if (ret)
+		class_unregister(&firmware_class);
+
+	return ret;
 }
 
 void unregister_sysfs_loader(void)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-08-03  1:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03  1:29 [PATCH v1] firmware_loader: Unwind initialization on sysfs failure Yuho Choi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox