From 556b06abb5dbae720d8923993f54f5b1ee9bb7e9 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Tue, 8 Dec 2009 17:39:03 -0200 Subject: [PATCH 1/1] . --- Makefile | 1 + test_list.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Makefile create mode 100644 test_list.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e257335 --- /dev/null +++ b/Makefile @@ -0,0 +1 @@ +obj-m += test_list.o diff --git a/test_list.c b/test_list.c new file mode 100644 index 0000000..ced1a73 --- /dev/null +++ b/test_list.c @@ -0,0 +1,43 @@ +#include +#include + +MODULE_LICENSE("GPL"); + +struct test +{ + int val; + struct list_head l; +}; + +static struct test *mylist; + +LIST_HEAD(test_head); + +static int test_list_init(void) +{ + struct list_head *l; + int i; + mylist = kmalloc(sizeof(struct test) * 16, GFP_KERNEL); + for (i = 0; i < 16; i++) + mylist[i].val = i; + if (mylist == NULL) + return ENOMEM; + list_add_tail(&mylist[0].l, &test_head); + list_add_tail(&mylist[1].l, &test_head); + list_add_tail(&mylist[2].l, &test_head); + list_add_tail(&mylist[3].l, &test_head); + list_del(&mylist[1].l); + list_for_each(l, &test_head) { + struct test *h = list_entry(l, struct test, l); + printk(KERN_DEBUG "%d\n", h->val); + } + return 0; +} + +static void test_list_exit(void) +{ + kfree(mylist); +} + +module_init(test_list_init); +module_exit(test_list_exit); -- 2.20.1