Thread: Unable to remove module after oops?

  1. #1
    Registered User
    Join Date
    Dec 2011

    Unable to remove module after oops?

    Is there a way to forcibly remove a module from the kernel, because even "rmmod -f" fails to do so? After I insert a module and it emits an oops, the computer is fully usable except for the fact that I cannot remove the module again, and it only goes away upon a restart. It says that the module is "in use", and it seems to be owned by level 0 or 1 every time.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    I would never continue to use a machine after an oops...

    The module is in charge of its own reference count, which allows the kernel to unload it. If the module is malfunctioning there is nothing the rest of the kernel can do about it. Fix the buggy module.

    Edit: From the LDD book:

    You won't be able to unload a module if you lose track of the usage count. This situation may very well happen during development, so you should keep it in mind. For example, if a process gets destroyed because your driver dereferenced a NULL pointer, the driver won't be able to close the device, and the usage count won't fall back to zero. One possible solution is to completely disable the usage count during the debugging cycle by redefining both MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT to no-ops. Another solution is to use some other method to force the counter to zero (you'll see this done in the section "Using the ioctl Argument" in Chapter 5, "Enhanced Char Driver Operations"). Sanity checks should never be circumvented in a production module. For debugging, however, sometimes a brute-force attitude helps save development time and is therefore acceptable.
    See here: Linux Device Drivers, 2nd Edition: Chapter 2: Building and Running Modules
    Last edited by brewbuck; 12-30-2011 at 03:34 PM.
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);

  3. #3
    Registered User
    Join Date
    Dec 2011
    Thanks for the reply, and yes, I'm just doing this for debugging. I defined both of the macros to no-ops (0x00, right?), and it still failed to remove the module.

    Fortunately, I fixed the crashing, but I'd still like a solution for future issues. I read the online book that you'd linked, and ioctl doesn't sound like the best solution for the problem, perhaps I'm not implementing it right? I found the following code:

    while (MOD_IN_USE)        MOD_DEC_USE_COUNT;      MOD_INC_USE_COUNT;
    Is there a way to make this run automatically, on start?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windbg unable to load unloaded module list
    By Mario F. in forum Tech Board
    Replies: 8
    Last Post: 02-27-2011, 06:51 PM
  2. Remove a specific char and remove multiple spaces
    By stam in forum C++ Programming
    Replies: 9
    Last Post: 12-18-2010, 07:50 AM
  3. Oops
    By Mario F. in forum General Discussions
    Replies: 20
    Last Post: 03-24-2010, 10:46 AM
  4. Oops.
    By adrianxw in forum A Brief History of
    Replies: 2
    Last Post: 03-18-2004, 10:01 AM
  5. Oops
    By Flick in forum C++ Programming
    Replies: 5
    Last Post: 04-26-2003, 02:20 AM