0
votes

in code below I am trying to create a linked list in kerenl module, why do I get below error?

error(in LIST_HEAD(root->list)): expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘->’ token


typedef struct
{
     int a;
     char* b;
     struct list_head list;

}mystruct;

void add(mystruct* r)
{
   mystruct* tmp = (mystruct*)vmalloc(sizeof(mystruct));
   tmp->a = 110;
   tmp->b = (char*)vmalloc(sizeof(char)*10);
   list_add_tail(&(tmp->list),&(r->list));
}
int init_module(void)
{
  mystruct *root;
  LIST_HEAD(root->list);
  add(root);
}
1

1 Answers

2
votes

@Sweet, I have modified the above code as below,

int list_init(void)
{
  mystruct *root = (mystruct*)kmalloc(sizeof(mystruct), GFP_KERNEL); //or mystruct root;

  INIT_LIST_HEAD(&root->list); //or INIT_LIST_HEAD(&root.list);
  add(root);

  return 0;
}

It works fine for me, please try at your end :-).