linux kernel - Deleting a sysfs entry -


i trying learn sysfs , trying write simple sysfs directory. code below

static struct kobject *example_kobject;  static int __init mymodule_init (void) {     pr_debug("module initialized \n");     example_kobject = kobject_create_and_add("kobject_example",                                              kernel_kobj);     if(!example_kobject)             return -enomem;     return 0;  }   static void __exit mymodule_exit (void)  {      pr_debug ("module un initialized \n");     //  kobject_put(example_kobject); <-- forgot delete  }   module_init(mymodule_init);  module_exit(mymodule_exit); 

as shown in mymodule_exit, had mistake forgot uncomment code , inserted , rmmod module.

now when try insert module again, initialization failing entry present.

i know, not make sense allow userspace remove entry kernel made. but, still wondering if there other way remove particular /sys/kernel/kobject_example entry other rebooting box.

firstly, merely doing kobject_put() not enough, must use kobject_del() instead. kobject_put() not complete clean-up. in case, since kobject_example file (not dir), mere 'put' still leave entry in parent dir (kset).

if must, there away remove such entry without reboot, , writing module that. here module should doing:

/* find kobj path , parent kset */ kobj = kset_find_obj(kernel_kobj->kset, "kobject_example"); ... /* check kobj not null etc. */ ... /* remove sysfs entry */ kobject_del(kobj); 

this delete sysfs entry. reboot easy, nifty when system not have option go out of service.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -