Skip to contentSkip to conversation

ldd module param practice

DISCUSSION runcoderen 3 participants 3 messages Aug 22, 2010 – Aug 23, 2010

lore
Share & tools
lore

runcoderen

author
#0 lore raw

hi all:

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

MODULE_LICENSE("Dual BSD/GPL");

static char *whom = "world";
static char howmany = 1;

module_param(howmany, int, S_IRUGO);
module_param(whom, charp, S_IRUGO);

static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}

static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

insmod hellop.ko howmany=10 whom="Mom"

this code I want to printk "hello Mom" 10 times.

but it doesn't work. so I modified static int howmany = 10, it doesn't work either.
I don't know whether it's my wronging use?

Signature · 3 lines
/****************************************
http://runcoderen.wordpress.com/
****************************************/
#1 lore raw
Quoted 11 lines · runcoderen

hi all:

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

MODULE_LICENSE("Dual BSD/GPL");

static char *whom = "world"; static char howmany = 1;

What happens if you make 'howmany' an int instead of a char?

Quoted 18 lines

module_param(howmany, int, S_IRUGO); module_param(whom, charp, S_IRUGO);

static int hello_init(void) {
printk(KERN_ALERT "Hello, world\n"); return 0; }

static void hello_exit(void) {
printk(KERN_ALERT "Goodbye, cruel world\n"); }

module_init(hello_init); module_exit(hello_exit);

insmod hellop.ko howmany=10 whom="Mom"

this code I want to printk "hello Mom" 10 times.

but it doesn't work. so I modified static int howmany = 10, it doesn't work either. I don't know whether it's my wronging use?

#2 lore raw
In reply to runcoderen
Quoted 25 lines · runcoderen

hi all:

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

MODULE_LICENSE("Dual BSD/GPL");

static char *whom = "world";
static char howmany = 1;

module_param(howmany, int, S_IRUGO);
module_param(whom, charp, S_IRUGO);

static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}

static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}

Quoted 6 lines

module_init(hello_init);
module_exit(hello_exit);

insmod hellop.ko howmany=10 whom="Mom"

this code I want to printk "hello Mom" 10 times.

How can it work? You neither have a loop nor use 'whom' in your hello_init()...

You need:

statick int hello_init(void)
{
int i;
for (i=0; i<howmany; i++)

      printk(KERN_WARNING "Hello, %s\n", whom);

return 0;
}