segmentation fault in list_for_each
I am writing a test module which uses linkedlist using list.h.
I use list_add to add entries in linkedlist, but when i try to iterate the list i get segmentation fault.
I am providing the code below. Could someone help me to fix the problem.
Code
-------
int init_module()
{
int returnValue ;
returnValue = register_chrdev(22, "xxx", &xxx_fops)))
TestList("hello_world00");
TestList("helloworld11");
IterateList();
return 0;
}
int cleanup_module()
{
unregister_chrdev(22,"xxx");
}
void TestList(char *data_in)
{
struct directoryList dirStruct;
my_memcpy(dirStruct.dirName,data_in,strlen(data_in) +1);
list_add(&dirStruct.list,&initList);
printk(" DATA ADDED %s \n", dirStruct.dirName); // i am receiving this print in the log
}
void IterateList()
{
struct list_head *tmp;
list_for_each(tmp, &initList)
{
struct directoryList *iterateList = list_entry(tmp, struct directoryList, list);
printk( " ITERATELIST DIR VALUE %s \n" , iterateList->dirName);
}
}
/*************** LOG OUTPUT IS PROVIDED BELOW *********************/
DATA ADDED hello_world00
DATA ADDED helloworld11
ITERATELIST DIR VALUE helloworld11
last message repeated 661 times
Unable to handle kernel NULL pointer dereference at virtual address 00000001
printing eip:
e0ade288
.... it goes on ....
|