My objective is to execute kernel thread from my driver's probe function only ONCE which performs firmware downloading.
Putting up sample code(not actual one) for simplicity,
#include<linux/module.h>
#include<linux/init.h>
#include<linux/kthread.h>
MODULE_LICENSE("GPL");
struct task_struct *kthread;
static int thread_func(void* data)
{
printk("In %s function\n", __func__);
return 0;
}
static int hello_init(void)
{
int ret = 0;
printk("Hello World\n");
kthread = kthread_run(thread_func,
NULL, "kthread-test");
if (IS_ERR(kthread)) {
ret = PTR_ERR(kthread);
printk("Unable to run kthread err %d\n", ret);
return ret;
}
return 0;
}
static void hello_exit(void)
{
printk("Bye World\n");
}
I am not using any of following because:
kthread_should_stop()- used for continuous execution which I do not wantkthread_stop(struct task_struct *thread)- if included in module exit function, causes kernel panic since thread was already terminated after executing once
Is this a correct approach? if not please suggest