Check if Linux Kernel Module is working

I wrote a kernel module that creates an entry in / proc / and performs some other tasks. I want to modify an existing kernel module to check if my module is working and to execute some sentences depending on it (or execute others if it is not running).

Any tips on how to do this?

+3
source share
1 answer

kernel/module.cprovides a function that is likely to do what you need; you first need to lock module_mutexand then call find_module()with the name of your module. The result will be a pointer to struct modulewhich the named module describes - or NULLif the module is not loaded:

/* Search for module by name: must hold module_mutex. */
struct module *find_module(const char *name)
{
        struct module *mod;

        list_for_each_entry(mod, &modules, list) {
                if (strcmp(mod->name, name) == 0) 
                        return mod;
        }
        return NULL;
}
EXPORT_SYMBOL_GPL(find_module);
+4
source

All Articles