2013-08-04 95 views
0

下面的代碼我想在kerenl模塊中創建一個鏈表,爲什麼我會得到下面的錯誤?內核鏈表初始化

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); 
} 

回答

2

@Sweet,我作如下修改上面的代碼,

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; 
} 

它工作正常,我請你到底嘗試:-)。