简体   繁体   中英

Use of timer_list in Linux kernel module causes system to crash

I'm writing a kernel (2.6.28) module that uses a dynamic timer. I'm using the timer_list structure as follows:

struct timer_list our_timer;
init_timer(&our_timer);
our_timer.function = handleFlowTimer;
our_timer.expires = jiffies + 2000;
our_timer.data = 0;
add_timer(&our_timer);

void handleFlowTimer(unsigned long data)
{
    //do nothing
}

This works ok for about 2 seconds until the timer expires. Then the system crashes. I've also tried something like this with the same result:

struct timer_list our_timer = TIMER_INITIALIZER(handleFlowTimer, 0, 0);
mod_timer(&our_timer, jiffies + 2000);

Any help would be greatly appreciated!

our_timer is allocated on stack and you pass a pointer to it. It is most probable that our_timer gets out of scope, overwritten, and after 2 seconds the value our_timer.function is invalid.

Make our_timer a static variable or use kmalloc .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM