Hello all,

I write a small linux module on Suse server Interprise 9.0 to test out linux workqueue which is shown below. The function MyThread gets called but the data passed to it is wrong. Do you have any idea why? Any help is greatly appreciated. Thank you in advance.

#include <linux/workqueue.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>

MODULE_LICENSE("Dual BSD/GPL");

void MyThread(void *data);
static int datapassed;
static struct work_struct *ncbWorkStruct;

static int __init TestNcb_init(void)
{
datapassed = 0x99;

ncbWorkStruct = kmalloc(sizeof(struct work_struct), GFP_ATOMIC);
INIT_WORK(ncbWorkStruct, MyThread, &datapassed);
schedule_work(ncbWorkStruct);
printk(KERN_ALERT "End Init\n");
return 0;
}

static void __exit TestNcb_exit(void)
{
printk(KERN_ALERT "End Exit\n");
}


void MyThread(void *data)
{
int local = (int)*((int *)data);

/* local is supposed to be 0x99 but it is fd968000 which is wrong */
printk("&&& DataPassed is %x\n", local);
printk("&&& Data is %x\n", datapassed);
return;
}

module_init(TestNcb_init);
module_exit(TestNcb_exit);