user3452214
user3452214

Reputation: 175

lsmod showing module is used by -2

I am trying to pass command line parameters using following code

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/moduleparam.h>

static int nilvar=0;
static int nilvar2=0;
int rollcalls[5];// = {0};
char classname[10];// = "math";

module_param_named (var,nilvar2,int,0644);
module_param (nilvar,int,0644);
module_param_array_named(present,rollcalls,int,5,0644);
module_param_string(subject,classname,10,0644);

int init_module(void)
{
    printk(KERN_INFO"1) nilvar = %d\n 2) nilvar2 = %d",nilvar,nilvar2);
    printk(KERN_INFO/*NOTICE*/"ROLLCALLS = %d ,%d ,%d ,%d",rollcalls[0],rollcalls[1],rollcalls[2],rollcalls[3]);
    printk(KERN_INFO/*DEBUG*/"classname = %s",classname);
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "Bye....\n");
}

MODULE_LICENSE("GPL");

after make ,I am passing my arguments by

insmod module1.ko var=5 nilvar=6 present=1 2 3 4 subject=physics

I don't know exactly what is happening but now lsmod shows module used by -2. (actually no module is dependent on this module)

so where I am wrong ? and if we want to modify all this variables as a structure elements, then how to use module_param() macro for it?

Upvotes: 1

Views: 1061

Answers (1)

Gautham Kantharaju
Gautham Kantharaju

Reputation: 1763

@user3452214, instead of module_param_array_named(present, rollcalls, int, **5**, 0644); use module_param_array_named(present, rollcalls, int, **&count**, 0644); added one more variable i.e. static unsigned int count which keep count of the number written to the array. We need to pass the pointer as explained in the moduleparam.h, thus cannot pass numerical value for this parameter. It works fine!!!. Hope it solves your problem.

/**
 * module_param_array_named - renamed parameter which is an array of some type
 * @name: a valid C identifier which is the parameter name
 * @array: the name of the array variable
 * @type: the type, as per module_param()
 * @nump: optional pointer filled in with the number written
 * @perm: visibility in sysfs
 *
 * This exposes a different name than the actual variable name.  See
 * module_param_named() for why this might be necessary.
 */
#define module_param_array_named(name, array, type, nump, perm)

Upvotes: 2

Related Questions