tags:

views:

398

answers:

1

Hi there,

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!

+3  A: 

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.

Adrian Panasiuk
Ha, just figured it out then saw your response. Damn that stack!!! Thanks!
Tim Merrifield