2
votes

I have written one basic linux kernel module with init and exit function.

Then tried the to compile the LKM without init function and it got successfully compiled and inserted inside the kernel. Then removed the same using rmmod and it got removed and got the print in dmesg which I have put inside exit function.

Same procedure followed for the module without exit function and with init function. It got inserted successfully but when I am trying to remove it showing error "could not remove module:Device or resource busy".

Not able to understand the above behavior.Why module without init function is working fine while module without exit function is not. Can somebody explain the same ?

Thanks,

1

1 Answers

3
votes

There is a check in the kernel (/kernel/module.c go through delete_module syscall), If you have a module_init func in your module then it must strictly have exit func to unload, If there isnt -EBUSY is returned.

This check is because, its assumed you have done some resource allocation in init function and you have to release them in the exit function!