[PATCH 20/27] ip2: avoid add_timer with pending timer

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Alan Cox
Date: Friday, October 10, 2008 - 3:50 am

From: Akinobu Mita <akinobu.mita@gmail.com>

add_timer() is not suppose to be called when the timer is pending.
ip2 driver attempts to avoid that condition by setting and resetting
a flag (TimerOn) in timer function. But there is some gap between
add_timer() and setting TimerOn.

This patch fix this problem by using mod_timer() and remove TimerOn
which has been unnecessary by this change.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: Alan Cox <alan@redhat.com>
---

 drivers/char/ip2/ip2main.c |   19 ++++---------------
 1 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index 39269d1..66f52a2 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -249,7 +249,6 @@ static unsigned long bh_counter;
  */
 #define  POLL_TIMEOUT   (jiffies + 1)
 static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
-static char  TimerOn;
 
 #ifdef IP2DEBUG_TRACE
 /* Trace (debug) buffer data */
@@ -374,11 +373,7 @@ static void __exit ip2_cleanup_module(void)
 	int err;
 	int i;
 
-	/* Stop poll timer if we had one. */
-	if (TimerOn) {
-		del_timer(&PollTimer);
-		TimerOn = 0;
-	}
+	del_timer_sync(&PollTimer);
 
 	/* Reset the boards we have. */
 	for (i = 0; i < IP2_MAX_BOARDS; i++)
@@ -774,10 +769,8 @@ static int __init ip2_loadmain(void)
 		}
 		if (ip2config.irq[i] == CIR_POLL) {
 retry:
-			if (!TimerOn) {
-				PollTimer.expires = POLL_TIMEOUT;
-				add_timer(&PollTimer);
-				TimerOn = 1;
+			if (!timer_pending(&PollTimer)) {
+				mod_timer(&PollTimer, POLL_TIMEOUT);
 				printk(KERN_INFO "IP2: polling\n");
 			}
 		} else {
@@ -1283,16 +1276,12 @@ ip2_poll(unsigned long arg)
 {
 	ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 );
 
-	TimerOn = 0; // it's the truth but not checked in service
-
 	// Just polled boards, IRQ = 0 will hit all non-interrupt boards.
 	// It will NOT poll boards handled by hard interrupts.
 	// The issue of queued BH interrupts is handled in ip2_interrupt().
 	ip2_polled_interrupt();
 
-	PollTimer.expires = POLL_TIMEOUT;
-	add_timer( &PollTimer );
-	TimerOn = 1;
+	mod_timer(&PollTimer, POLL_TIMEOUT);
 
 	ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
 }

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/27] First block of the tty backlog, Alan Cox, (Fri Oct 10, 3:36 am)
[PATCH 04/27] epca: call tty_port_init, Alan Cox, (Fri Oct 10, 3:37 am)
[PATCH 13/27] Fix oti6858 debug level, Alan Cox, (Fri Oct 10, 3:49 am)
[PATCH 14/27] Char: cyclades. remove bogus iomap, Alan Cox, (Fri Oct 10, 3:49 am)
[PATCH 15/27] Char: sx, fix io unmapping, Alan Cox, (Fri Oct 10, 3:49 am)
[PATCH 16/27] Char: merge ip2main and ip2base, Alan Cox, (Fri Oct 10, 3:50 am)
[PATCH 17/27] ip2, cleanup globals, Alan Cox, (Fri Oct 10, 3:50 am)
[PATCH 18/27] ip2, fix sparse warnings, Alan Cox, (Fri Oct 10, 3:50 am)
[PATCH 19/27] ip2, init/deinit cleanup, Alan Cox, (Fri Oct 10, 3:50 am)
[PATCH 20/27] ip2: avoid add_timer with pending timer, Alan Cox, (Fri Oct 10, 3:50 am)
[PATCH 23/27] nozomi: Fix close on error, Alan Cox, (Fri Oct 10, 3:51 am)
[PATCH 25/27] usb: fix pl2303 initialization, Alan Cox, (Fri Oct 10, 3:51 am)
Should &lt;linux/serial.h&gt; define __u32?, walt, (Sun Dec 28, 3:24 pm)
Re: Should &lt;linux/serial.h&gt; define __u32?, Alan Cox, (Sun Dec 28, 5:53 pm)
Re: Should &lt;linux/serial.h&gt; define __u32?, Mike Frysinger, (Mon Dec 29, 5:35 am)