Linux Device Driver code to load another module

Linux Kernel code can load module whenever needed.

int request_module(const char *module_name);

Header File: <linux/kmod.h>

Source Code: kernel/kmod.c

request_module is synchronous, it will sleep until the attemp to load the module has been completed.

When the kernel code calls request_mode(), a new kernel thread is created, which runs modprobe program in the user context.

Code:


#include <linux/module.h> /* for MODULE_* */
#include <linux/printk.h> /* for pr_info */
static int __init mod_init(void)
{
if (request_module("crc7") > 0)
pr_info("request_module failed to load\n");
else
pr_info("request_module loaded successfully\n");
return 0;
}
static void __exit mod_exit(void)
{
}
module_init(mod_init);
module_exit(mod_exit);

Output:





Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto