Skip to contentSkip to conversation

clockevents: Add error handling and rollback in tick_init_sysfs()

PATCH In review Zhan Xusheng 2 participants 2 messages Feb 10 – Feb 11 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clockevents: Add error handling and rollback in tick_init_sysfs()

Ensure proper error handling and logging when creating device files for each CPU. If device creation or file creation fails, the function now properly unregisters the device and removes any previously created files to maintain system consistency.

---
 kernel/time/clockevents.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
kernel/time/clockevents.c +16 -4
index eaae1ce9f060..daa875f1d37c 100644
@@ -756,12 +756,24 @@ static int __init tick_init_sysfs(void)
 		dev->id = cpu;
 		dev->bus = &clockevents_subsys;
 		err = device_register(dev);
-		if (!err)
-			err = device_create_file(dev, &dev_attr_current_device);
-		if (!err)
-			err = device_create_file(dev, &dev_attr_unbind_device);
 		if (err)
 			return err;
+
+		err = device_create_file(dev, &dev_attr_current_device);
+		if (err)
+			goto err_unregister;
+
+		err = device_create_file(dev, &dev_attr_unbind_device);
+		if (err)
+			goto err_remove_file;
+
+		continue;
+
+err_remove_file:
+		device_remove_file(dev, &dev_attr_current_device);
+err_unregister:
+		device_unregister(dev);
+		return err;
 	}
 	return tick_broadcast_init_sysfs();
 }
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 16 lines · Zhan Xusheng
kernel/time/clockevents.c +6 -4
@@ -756,12 +756,24 @@ static int __init tick_init_sysfs(void)
 		dev->id = cpu;
 		dev->bus = &clockevents_subsys;
 		err = device_register(dev);
-		if (!err)
-			err = device_create_file(dev, &dev_attr_current_device);
-		if (!err)
-			err = device_create_file(dev, &dev_attr_unbind_device);
 		if (err)
 			return err;
+
+		err = device_create_file(dev, &dev_attr_current_device);
+		if (err)
+			goto err_unregister;
+
+		err = device_create_file(dev, &dev_attr_unbind_device);

kernel/time/clockevents.c static int __init tick_init_sysfs(void) · line 776

Quoted 10 lines
kernel/time/clockevents.c +10 -0
+		if (err)
+			goto err_remove_file;
+
+		continue;
+
+err_remove_file:
+		device_remove_file(dev, &dev_attr_current_device);
+err_unregister:
+		device_unregister(dev);
+		return err;

So this leaves already created per CPU files and devices around which is inconsistent as well.

So what's the point of this half baked cleanup?

If this fails and it only can fail because of out of memory then the system is doomed anyway. Cleanup up a couple of kilobytes wont make a difference at all

Thanks,

tglx