Skip to contentSkip to conversation

clocksource: Unregister subsystem on device registration failure

PATCH Applied Yuho Choi 2 participants 2 messages Jul 2 – Jul 7 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 clocksource: Unregister subsystem on device registration failure

init_clocksource_sysfs() registers the clocksource subsystem before registering the clocksource device. If device_register() fails, the function returns the error while leaving the subsystem registered.

Unregister the clocksource subsystem on that failure path so the successful subsystem registration is unwound before returning.

Fixes d369a5d8fc70 ("clocksource: convert sysdev_class to a regular subsystem")
---
 kernel/time/clocksource.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/time/clocksource.c +6 -2
index e48c4d379a7c..5a786b3c778c 100644
@@ -1566,8 +1566,12 @@ static int __init init_clocksource_sysfs(void)
 {
 	int error = subsys_system_register(&clocksource_subsys, NULL);
 
-	if (!error)
-		error = device_register(&device_clocksource);
+	if (error)
+		return error;
+
+	error = device_register(&device_clocksource);
+	if (error)
+		bus_unregister(&clocksource_subsys);
 
 	return error;
 }
Signature · 1 line
2.43.0
merge bot Applied
#1 lore raw
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     3dee6537e728bd8137fda6eaf859f26e685943f7
Gitweb:        https://git.kernel.org/tip/3dee6537e728bd8137fda6eaf859f26e685943f7
Author:        Yuho Choi <[email protected]>
AuthorDate:    Thu, 02 Jul 2026 17:57:33 -04:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Tue, 07 Jul 2026 23:26:58 +02:00

clocksource: Unregister subsystem on device registration failure

init_clocksource_sysfs() registers the clocksource subsystem before registering the clocksource device. If device_register() fails, the function returns the error while leaving the subsystem registered.

Unregister the clocksource subsystem on that failure path so the successful subsystem registration is unwound before returning.

Fixes d369a5d8fc70 ("clocksource: convert sysdev_class to a regular subsystem")
---
 kernel/time/clocksource.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/time/clocksource.c +6 -2
index 78c91b0..f1253f5 100644
@@ -1565,8 +1565,12 @@ static int __init init_clocksource_sysfs(void)
 {
 	int error = subsys_system_register(&clocksource_subsys, NULL);
 
-	if (!error)
-		error = device_register(&device_clocksource);
+	if (error)
+		return error;
+
+	error = device_register(&device_clocksource);
+	if (error)
+		bus_unregister(&clocksource_subsys);
 
 	return error;
 }