#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "main.h"
#define err(msg) printk(KERN_INFO "%s failed.\n", msg)
static LIST_HEAD(list);
static int __init main_init(void)
{
struct list_struct *item;
int i, j;
struct list_struct *pos, *n;
for (i = 0; i < 10; i++) {
item = kzalloc(sizeof(struct list_struct), GFP_KERNEL);
if (item) {
item->num = i;
list_add_tail(&item->n_list, &list);
} else
err("kzalloc");
}
list_for_each_entry(pos, &list, n_list) {
printk(KERN_INFO "item->num = %d\n", item->num);
}
list_for_each_entry_safe(pos, n, &list, n_list) {
list_del(&pos->n_list);
kfree(pos);
}
return 0;
}
static void __exit main_exit(void)
{
}
module_init(main_init);
module_exit(main_exit);
MODULE_LICENSE("GPL");
阅读(3479) | 评论(0) | 转发(0) |