clocksource: Unregister subsystem on device registration failure
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.
--- kernel/time/clocksource.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/time/clocksource.c +6 -2
@@ -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
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.
--- kernel/time/clocksource.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/time/clocksource.c +6 -2
@@ -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; }