Not able to remove a loadable kernel module

Varda Elentári picture Varda Elentári · Jun 22, 2013 · Viewed 14.9k times · Source

I'm writing a loadable kernel module and trying to test it. After inserting it I was trying to remove it using rmmod xxx command, but I get an error saying module xxx is in use and the module gets stuck and I can't remove it. Any idea how to remove the module without rebooting the entire machine ? (linux Kernel v. 3.5.0)

Note: rmmod -f prints Error: device or resource busy

Answer

Benjamin Leinweber picture Benjamin Leinweber · Jun 23, 2013

This only happens to me when there is a bug in my driver which is causing the code in the module to panic or crash in some way. In my experience once this happens reboot is the only possible course.

As I said, the kernel usually panics so you should check out dmesg after inserting it or running you application to exercise it. I'm not certain but it might be possible that if the driver doesn't release a mutex this behavior will happen as well.