Created
May 2, 2015 18:14
-
-
Save kadamski/69ea849f9564d0b9a8c1 to your computer and use it in GitHub Desktop.
Those kthread_stop will oops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> | |
#include <linux/kernel.h> | |
#include <linux/init.h> | |
#include <linux/delay.h> | |
#include <linux/miscdevice.h> | |
#include <linux/fs.h> | |
#include <linux/uaccess.h> | |
#include <linux/kthread.h> | |
#include <linux/ratelimit.h> | |
struct task_struct *thread; | |
int func(void *arg) { | |
static int i = 0; | |
printk("thread %d\n", i++); | |
return 0; | |
} | |
static int __init hello_init(void) | |
{ | |
int i = 0; | |
thread = kthread_run(&func, NULL, "thread%d", i); | |
if (thread) { | |
msleep(10000); | |
kthread_stop(thread); // This will oops | |
} | |
return 0; | |
} | |
static void __exit hello_exit(void) | |
{ | |
/* if (thread) */ | |
/* kthread_stop(thread); // This will oops */ | |
} | |
module_init(hello_init); | |
module_exit(hello_exit); | |
MODULE_LICENSE("GPL"); | |
MODULE_AUTHOR("Krzysztof Adamski <k@japko.eu>"); | |
MODULE_DESCRIPTION("thread_stop_oops"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment