#include #include #include #include #include #include #include #include #include #include #include #include #include #define COUNT 0x20 char *p[COUNT]; struct task_struct *tsk; int another_thread(void *arg) { int i = 0; for (i = 0; i < COUNT-2; i+=2) { pr_info("kfree i: %d, %p\n", i, p[i]); kfree(p[i]); } msleep(10); kfree(p[COUNT-2]); return 0; } static int __init test_init(void) { int i = 0; for (i = 0; i < COUNT-1; i++) p[i] = kmalloc(4096, GFP_KERNEL); p[COUNT-1] = p[COUNT-3]; tsk = kthread_run(another_thread, NULL, "another_thread"); if (IS_ERR(tsk)) pr_info("kthread_run err\n"); for (i = 1; i < COUNT-1; i+=2) { pr_info("kfree i: %d, %p\n", i, p[i]); kfree(p[i]); } msleep(100); kfree(p[COUNT-1]); return 0; } static void __exit test_exit(void) { if (!IS_ERR(tsk)) kthread_stop(tsk); return; } module_init(test_init); module_exit(test_exit); MODULE_LICENSE("GPL");