linux-kernellinux-device-driverkernel-modulepermanent

how to resolve module marked permanent in LKM


I have written a simple jiffies code and when I try to do rmmod I get

ERROR: Removing 'jiffi_module': Device or resource busy

so I did bit of research and found by doing lsmod below symptom of "permanent" being the problem which is caused by exit_function not being found.

Module                  Size  Used by
jiffi_module            1027  0 **[permanent]**

infact my make file do show me warning related to exit function

Warning when exit function is defined as

static void __exit
jif_exit(void)
{
    remove_proc_entry("jif", NULL);
}

warning: data definition has no type or storage class
warning: type defaults to ‘int’ in declaration of ‘modile_exit’
warning: parameter names (without types) in function declaration
warning: ‘jif_exit’ defined but not used

when I remove the __exit seems it atleast identifies jif_exit - so now the warning I get is

warning: data definition has no type or storage class
warning: type defaults to ‘int’ in declaration of ‘modile_exit’
warning: parameter names (without types) in function declaration

Reading through below Why is this kernel module marked at permanent on 2.6.39

it talks about gcc mismatch being a problem ? Can someone please help I am not able to debug it further ? Any pointers how to load module properly such that its not permanent?


Solution

  • Kernel module is marked as permanent (cannot be unloaded) if there is no exit function is defined for it.

    exit function accepts no arguments and return nothing and should be defined either with predefined name

    void cleanup_module(void)
    {
        ...
    }
    

    or with arbitrary name but registered with module_exit macro

    void <func_name>(void)
    {
        ...
    }
    
    module_exit(<func_name>);
    

    static, __exit and other attributes for exit function are optional.