Skip to content

Instantly share code, notes, and snippets.

@kadamski
Created May 2, 2015 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadamski/69ea849f9564d0b9a8c1 to your computer and use it in GitHub Desktop.
Save kadamski/69ea849f9564d0b9a8c1 to your computer and use it in GitHub Desktop.
Those kthread_stop will oops
#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