In the code for my Linux Kernel module, I create a kobject
, which becomes a directory in the /sys/ directory, and then create a sysfs
file in it. So it looks like /sys/KobjName/SysfsFile. This is the only file in that kobject
directory, and both the sysfs
file and the kobject
are to be deleted after the rmmod moduleX
command is executed.
Currently my clean_up code for moduleX
looks like
static void cleanup(void)
{
/* Remove test file */
if (file_ok)
sysfs_remove_file(kobj, &attributes.attr);
/* Remove /sys/ddttest directory */
if (kobj)
kobject_put(kobj);
}
where file_ok
is an integer of 0 or 1 representing if the sysfs_create_file(kobj, &attributes.attr)
function executed corrected (e.g. a file is created).
My question now is if it is even necessary to remove the sysfs
file before removing the kobject
. When navigating the file system in the user space, one can simply delete a directory, and that will remove all the files within it. Is that the case with kobject
file systems in the kernel space?