Re: Can not remove a module which has no cleanup_module()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi ...
I have created a small linux kernel module in Ubuntu 6.06 which has
'init_module()' but no 'cleanup_module()'.

<snip>
I loaded this module using the command 'sudo insmod start.ko'. But
when I try to remove 'start' from the kernel, I get this error
message.

$ sudo insmod start.ko
$ sudo rmmod start.ko
ERROR: Removing 'start': Device or resource busy

take a look on kernel/module.c in your kernel source (2.6.x) Around line 685, you'll see something like these:

/* If it has an init func, it must have an exit func to unload */
       if ((mod->init != NULL && mod->exit == NULL)
           || mod->unsafe) {
               forced = try_force_unload(flags);
               if (!forced) {
                       /* This module can't be removed */
                       ret = -EBUSY;
                       goto out;
               }
       }

Short story, the first "if" yields "true" result in your case, since exit function isn't declared (thus it's NULL). It then goes to do try_force_unload, but again it fails :

static inline int try_force_unload(unsigned int flags)
{
       int ret = (flags & O_TRUNC);
       if (ret)
               add_taint(TAINT_FORCED_RMMOD);
       return ret;
}


I have no idea what O_TRUNC is, but certainly in your case this flag is off so "forced" contains "false". In the end, you hit the "ret=-EBUSY" line and in user space you see the message "resource busy".

regards,

Mulyadi


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux