From: Michael Buesch <mb@bu3sch.de>
To: akpm@osdl.org
Cc: Jiri Benc <jbenc@suse.cz>,
netdev@vger.kernel.org, bcm43xx-dev@lists.berlios.de,
linville@tuxdriver.com, linux-kernel@vger.kernel.org
Subject: [PATCH] cancel_rearming_delayed_work infinite loop fix
Date: Tue, 11 Jul 2006 00:36:30 +0200 [thread overview]
Message-ID: <200607110036.31574.mb@bu3sch.de> (raw)
cancel_rearming_delayed_work{queue} is broken, because it is
possible to enter an infinite loop if:
We call the function on a work that is currently not executing or pending.
But, as this is a synchronization function and as its only purpose
is to synchronize the work, that should not loop infinite.
This patch rewrites the function.
It now first cancels the work, but throws the retval of that function
away, because it is meaningless in this context. (The retval is 1,
if the work was pending and 0, if not)
After that we flush the queue to make sure any work function returns.
Now, if it was indeed running, it rescheduled itself. That is caught
by the test_bit(). If it rescheduled itself, we have the schedule-delay
time to cancel the work again (without it rescheduling itself again).
So we redo the loop. Most likely it will succeed on the
second loop iteration at least.
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Index: wireless-dev-dscapeports/kernel/workqueue.c
===================================================================
--- wireless-dev-dscapeports.orig/kernel/workqueue.c 2006-06-13 14:44:16.000000000 +0200
+++ wireless-dev-dscapeports/kernel/workqueue.c 2006-07-11 00:19:06.000000000 +0200
@@ -461,8 +461,10 @@
void cancel_rearming_delayed_workqueue(struct workqueue_struct *wq,
struct work_struct *work)
{
- while (!cancel_delayed_work(work))
+ do {
+ cancel_delayed_work(work);
flush_workqueue(wq);
+ } while (test_bit(0, &work->pending));
}
EXPORT_SYMBOL(cancel_rearming_delayed_workqueue);
--
Greetings Michael.
next reply other threads:[~2006-07-10 22:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-10 22:36 Michael Buesch [this message]
2006-07-11 10:13 ` [PATCH] cancel_rearming_delayed_work infinite loop fix Herbert Xu
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=200607110036.31574.mb@bu3sch.de \
--to=mb@bu3sch.de \
--cc=akpm@osdl.org \
--cc=bcm43xx-dev@lists.berlios.de \
--cc=jbenc@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=netdev@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).