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
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()