All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Valdis Klētnieks" <valdis.kletnieks@vt.edu>
To: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: deleting timer that re-registers itself
Date: Tue, 04 May 2021 12:17:56 -0400	[thread overview]
Message-ID: <323231.1620145076@turing-police> (raw)
In-Reply-To: <CAB=+i9QMD-PxCgR6sOBU+6ddtiMsqFQ5_bLTok=4q509cdE1sA@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 981 bytes --]

On Tue, 04 May 2021 23:59:12 +0900, Hyeonggon Yoo said:
> Does del_timer work well for timers that re-registers itself?
> what if the timer is currently running, and del_timer is called,
> and the running timer re-registers itself?

Minor nit: while the timer is running, there's no problem.
When the timer has *expired* and timer_callback() is running
is when you have a race condition.

So who's going to call del_timer()? The only thing that does that is
timer_exit. Soo...  Apply some silly locking:

static int exiting = 0;

void timer_callback(struct timer_list *timer) {
        struct timer_data *data = from_timer(data, timer, timer);
        data->value++;
        printk(KERN_INFO "[%s] value is = %d\n", __func__, data->value);
        if (!exiting)
                mod_timer(timer, jiffies + DELAY);
}

void __exit timer_exit(void) {
        exiting = 1;
        int ret = del_timer(&data.timer);
        printk("[%s] deleting timer..., ret = %d\n", __func__, ret);
}

[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  reply	other threads:[~2021-05-04 16:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04 14:59 deleting timer that re-registers itself Hyeonggon Yoo
2021-05-04 16:17 ` Valdis Klētnieks [this message]
2021-05-04 16:28   ` Greg KH
2021-05-04 16:35   ` Valdis Klētnieks
2021-05-04 17:01     ` Greg KH
2021-05-05  7:22       ` Hyeonggon Yoo
2021-05-04 16:36   ` Hyeonggon Yoo
2021-05-04 16:41     ` Hyeonggon Yoo
2021-05-04 16:47       ` Hyeonggon Yoo

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=323231.1620145076@turing-police \
    --to=valdis.kletnieks@vt.edu \
    --cc=42.hyeyoo@gmail.com \
    --cc=kernelnewbies@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.