Hello,
I have written a kernel module that uses kernel timers.If i don't declare the variable mytimer as static the system hangs.But if i give it static then it works when i call function set_timer only once ,if i call it multiple times then the system hangs.I am unable to locate the fault
the code goes like this:
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/sched.h>
#include<linux/timer.h>
void timer_timeout(int c)
{
struct timeval timecount;
do_gettimeofday(&timecount);
printk(KERN_INFO "\ntimer%d expired at :%ld seconds %ld microseconds",c,timecount.tv_sec,timecount.tv_usec);
}
void set_timer(void)
{
static struct timer_list mytimer;
static int i=1;
struct timeval timecount;
init_timer(&mytimer);
mytimer.expires=jiffies+2*HZ;
mytimer.data="">
mytimer.function=(void*)timer_timeout;
add_timer(&mytimer);
do_gettimeofday(&timecount);
printk(KERN_INFO "\ntimer%d started at :%ld seconds %ld microseconds",i++,timecount.tv_sec,timecount.tv_usec);
return;
}
int time_init(void)
{
set_timer();
return 0;
}
void time_cleanup(void)
{
printk(KERN_INFO "\ntimer unloaded\n");
}
module_init(time_init);
module_exit(time_cleanup);
MODULE_LICENSE("GPL");