From: Greg KH <greg@kroah.com>
To: "Valdis Klētnieks" <valdis.kletnieks@vt.edu>
Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, kernelnewbies@kernelnewbies.org
Subject: Re: deleting timer that re-registers itself
Date: Tue, 4 May 2021 18:28:48 +0200 [thread overview]
Message-ID: <YJF2QPMCk8SBEySM@kroah.com> (raw)
In-Reply-To: <323231.1620145076@turing-police>
On Tue, May 04, 2021 at 12:17:56PM -0400, Valdis Klētnieks wrote:
> 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);
> }
That's mean, don't write buggy code as an example because then I'm going
to have to reject it when it gets submitted as a "real" driver :)
Hint, a "global" variable like this does not work like you expect it to
at all, sorry.
greg k-h
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
next prev parent reply other threads:[~2021-05-04 16:29 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
2021-05-04 16:28 ` Greg KH [this message]
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=YJF2QPMCk8SBEySM@kroah.com \
--to=greg@kroah.com \
--cc=42.hyeyoo@gmail.com \
--cc=kernelnewbies@kernelnewbies.org \
--cc=valdis.kletnieks@vt.edu \
/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.