Skip to contentSkip to conversation

firmware_loader: Unwind initialization on sysfs failure

PATCH In review Yuho Choi 2 participants 3 messages Aug 3 – Aug 6

Subsystems (2)
lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 firmware_loader: Unwind initialization on sysfs failure

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")
---
 drivers/base/firmware_loader/main.c  | 8 +++++++-
 drivers/base/firmware_loader/sysfs.c | 7 ++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/base/firmware_loader/main.c +7 -1
index 24213a0ea831..c2f7825dfc4a 100644
@@ -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;
drivers/base/firmware_loader/sysfs.c +6 -1
index 29a10d2ad537..d9deb0804f55 100644
@@ -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)
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 4 lines · 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.

Those are two separate issues, so it should also be two separate patches.

author
#2 lore raw
Quoted 2 lines · Danilo Krummrich

Those are two separate issues, so it should also be two separate patches.

I appreciate your time reviewing this. I'll send two separate patches.

Thanks,
Yuho