deleting timer that re-registers itself

Valdis Kl=?utf-8?Q?=c4=93?=tnieks valdis.kletnieks at vt.edu
Tue May 4 12:17:56 EDT 2021


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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20210504/b63284f3/attachment.sig>


More information about the Kernelnewbies mailing list