How to put a check in the code to ensure the inter kernel module dependency - Linux Kernel?

后端 未结 1 428
不知归路
不知归路 2021-01-15 23:41

I have two modules. I want the modules to be interdependent while doing insmod or rmmod. Currently, my module2 is dependent on module1. If I insert module1 then module2, it

相关标签:
1条回答
  • 2021-01-16 00:14

    You can use request_module API in module mod2 in which you want to use exported symbol, this loads required module on demand if not loaded previously.

    In module mod2,

    static int __init module_two_init_module(void)
    {
            int ret;
            const char *name;
            struct module * fmodule;
            pr_info("Module two started");
            name = "module_one";
            /* This will find module is loaded or not */
            fmodule = find_module(name); 
            if (fmodule == NULL) {
                    ret = request_module(name);
                    if (ret == 0) {
                            pr_info("Module one loaded");
                    }
            }
            /* Do rest of code here */
    

    Don't forget to increment module reference count using try_module_get()

    0 讨论(0)
提交回复
热议问题