timekeeping: Fix resource leak in tk_aux_sysfs_init() error paths
authorMalaya Kumar Rout <mrout@redhat.com>
Thu, 20 Nov 2025 15:02:13 +0000 (20:32 +0530)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 20 Nov 2025 15:40:48 +0000 (16:40 +0100)
commit7b5ab04f035f829ed6008e4685501ec00b3e73c9
treef28013914acd9cdc644462970e078b5c50f160c4
parent807e0d187da4c0b22036b5e34000f7a8c52f6e50
timekeeping: Fix resource leak in tk_aux_sysfs_init() error paths

tk_aux_sysfs_init() returns immediately on error during the auxiliary clock
initialization loop without cleaning up previously allocated kobjects and
sysfs groups.

If kobject_create_and_add() or sysfs_create_group() fails during loop
iteration, the parent kobjects (tko and auxo) and any previously created
child kobjects are leaked.

Fix this by adding proper error handling with goto labels to ensure all
allocated resources are cleaned up on failure. kobject_put() on the
parent kobjects will handle cleanup of their children.

Fixes: 7b95663a3d96 ("timekeeping: Provide interface to control auxiliary clocks")
Signed-off-by: Malaya Kumar Rout <mrout@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://patch.msgid.link/20251120150213.246777-1-mrout@redhat.com
kernel/time/timekeeping.c