1

I am trying to develop a kernel module which has to execute a thread.

I am facing an error while compiling the module.

This is the module:

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/kthread.h>  // for threads

static struct task_struct *thread1;

int thread_fn(void) {   
    while(1) {
        printk("Thread_fuction is running ...\n");
        msleep(2000);
    }
    return 0;
}

int thread_init(void) {
    char our_thread[8]="thread1";
    printk(KERN_INFO "in init");
    thread1 = kthread_create(thread_fn,NULL,our_thread);
    if((thread1)) {
        printk(KERN_INFO "in if");
        wake_up_process(thread1);
    }
    return 0;
}

void thread_cleanup(void) {
    int ret;
    ret = kthread_stop(thread1);
    if(!ret)
         printk(KERN_INFO "Thread stopped");
}

MODULE_LICENSE("GPL");   
module_init(thread_init);
module_exit(thread_cleanup);

And this is the error :

thread.c:25:26: error: passing argument 1 of ‘kthread_create_on_node’ from incompatible pointer type [-Werror=incompatible-pointer-types] thread1 = kthread_create(thread_fn,NULL,our_thread);

Could anyone help me to solve the problem?

2

1 Answer 1

3

In kernel source code you can see that kthread_create_on_node() function has first argument type: int (*threadfn)(void *data). But your "threadfn" int thread_fn (void) roughly speaking is of type int (*threadfn)(void).

So change (void) to (void *data).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.