All of lore.kernel.org
 help / color / mirror / Atom feed
From: dexter.haslem@gmail.com (Dexter Haslem)
To: kernelnewbies@lists.kernelnewbies.org
Subject: add_timer crashes the kernel,Why?
Date: Mon, 20 Dec 2010 07:15:57 -0700	[thread overview]
Message-ID: <4D0F651D.5020105@gmail.com> (raw)
In-Reply-To: <AANLkTi=5ZjwREM==JsTaUw5NrRYubNdWQHKSnjZ+ijBa@mail.gmail.com>

On 12/20/2010 2:08 AM, Mulyadi Santosa wrote:
> Hi :)
>
> On Mon, Dec 20, 2010 at 15:27, lijin liu<llj098@gmail.com>  wrote:
>> Hello everyone!
>>
>> I want to use the timer in my kernel module. I read the book  _Linux
>> kernel development 3rd version_  and LDD 3rd version.
>>
>> Both the two books tell me write the code like this:
>>
>> struct timer_list my_timer;
>> init_timer(&my_timer);
>>
>> my_timer.expires = jiffies + wait;
>> my_timer.data = 0;
>> my_timer.function=my_function;
>>
>> //active the timer:
>> add_timer(&timer);
>>
>>
>> When I insmod the module, the kernel crashed, and when I change my
>> code to *mod_timer* rather than add_timer.
>
> Hmmm, from http://lxr.linux.no/linux+v2.6.36/kernel/timer.c#L864, it reads:
> void add_timer(struct timer_list *timer)
> {
>          BUG_ON(timer_pending(timer));
>          mod_timer(timer, timer->expires);
> }
>
> thus, IMHO the error happened because there is other timer pending...
> somehow it is forbidden to add timer when other are still in queue in
> latest kernel
>

I believe add_timer just prevents creating duplicate timers from the 
same struct. I was actually thinking I had the same problem with timer 
code (following essential linux device drivers). But the issue was 
removing a module with an active timer will cause a crash.

Here is what I ended up with, a silly sample timer that chains itself 3 
times. It might be useful to OP: http://pastebin.com/v4rr3t50

-- 
-Dexter Haslem

      reply	other threads:[~2010-12-20 14:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-20  8:27 add_timer crashes the kernel,Why? lijin liu
2010-12-20  8:43 ` Raz
2010-12-20  9:06 ` Wick
     [not found] ` <AANLkTikY4+BqhjrNYiwR+1WrN53+_6JGiCkJ-kCTGL-B@mail.gmail.com>
2010-12-20  9:06   ` lijin liu
2010-12-20  9:33     ` Mulyadi Santosa
2010-12-20  9:08 ` Mulyadi Santosa
2010-12-20 14:15   ` Dexter Haslem [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D0F651D.5020105@gmail.com \
    --to=dexter.haslem@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.