歡迎您光臨本站 註冊首頁

內核鏈表問題求助

←手機掃碼閱讀     火星人 @ 2014-03-26 , reply:0

按照自己的想法編的一個內核鏈表創建、遍歷以及刪除的內褲模塊,創建鏈表的時候採用的是動態的方式,用arm-linux-編譯通過沒問題,但是下載到開發板上載入內核模塊就出來一大堆錯誤,求大神知道哪裡錯了。不說了,上程序。#include
#include
#include
#include
#include

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Li HongYu");
MODULE_DESCRIPTION("List Module");
MODULE_ALIAS("List module");

#define list_length 10

struct node
{
char name[100];
unsigned int num;
struct list_head entry;
};

struct node *new_node; //新申請的節點
struct node *tmp_node; //緩存節點
struct list_head *list; //頭結點指針
struct list_head *pos; //遍歷游標
struct list_head tmp_pos; //游標內容緩存

int mylist_init(void)
{
int i;

INIT_LIST_HEAD(list); //初始化頭結點

for(i=0;i {
new_node=kmalloc(sizeof(struct node),GFP_KERNEL);
memset(new_node,0,sizeof(struct node));
sprintf(new_node->name,"第%d節點",i+1);
new_node->num=i+1;
list_add(&(new_node->entry),list);
}



list_for_each(pos,list)
{
tmp_node = list_entry(pos,struct node,entry);
printk("<0> %d :%s\n",tmp_node->num,tmp_node->name);
}

return 0;
}

void mylist_exit(void)
{
list_for_each(pos,list)
{
tmp_pos = *pos;
tmp_node=list_entry(pos,struct node,entry);
list_del(pos);

kfree(tmp_node);

*pos = tmp_pos;
}
printk("<0> 鏈表刪除成功");
}

module_init(mylist_init);
module_exit(mylist_exit);

[火星人 ] 內核鏈表問題求助已經有438次圍觀

http://coctec.com/docs/linux/show-post-183080.html