. master
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Tue, 8 Dec 2009 19:39:03 +0000 (17:39 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Tue, 8 Dec 2009 19:39:03 +0000 (17:39 -0200)
Makefile [new file with mode: 0644]
test_list.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 (file)
index 0000000..ced1a73
--- /dev/null
@@ -0,0 +1,43 @@
+#include <linux/module.h>
+#include <linux/list.h>
+
+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);