v1mm3r
v1mm3r

Reputation: 57

error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]

I am working on a linux kernel module.

A struct tcpsp_conn is defined in the header file as follows:

struct tcpsp_conn {
...
struct timer_list timer; /* exp. timer*/
...
};

Then I declare a pointer to the structure and try to assign the function:

struct tcpsp_conn *cp;
cp->timer.function = tcpsp_conn_expire;

tcpsp_conn_expire function is defined in the same way as in the struct timer_list of the kernel:

static void tcpsp_conn_expire(unsigned long data)

I don't understand why am I getting this error: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types] cp->timer.function = tcpsp_conn_expire;

It doesn't look to have a problem with types.

Upvotes: 0

Views: 2569

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 65860

Type of your tcpsp_conn_expire function differs from the type of .function field of the timer_list structure.

In the newest kernel (since 4.15) this function-field is declared with struct timer_list * argument instead of unsigned long, as follows:

struct timer_list {
    ...
    void            (*function)(struct timer_list *);
    ...
};

Having such argument, you may obtain the pointer to the struct tcpsp_conn structure, into which the timer is embedded, with macro container_of.

Upvotes: 1

Related Questions