* [PATCH] ip2: avoid add_timer() with pending timer
@ 2008-07-14 2:49 Akinobu Mita
2008-07-14 13:33 ` Alan Cox
2008-07-14 17:04 ` Andrew Morton
0 siblings, 2 replies; 4+ messages in thread
From: Akinobu Mita @ 2008-07-14 2:49 UTC (permalink / raw)
To: linux-kernel; +Cc: Michael H. Warfield
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>
Cc: Michael H. Warfield <mhw@wittsend.com>
---
drivers/char/ip2/ip2main.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
Index: 2.6-mmotm/drivers/char/ip2/ip2main.c
===================================================================
--- 2.6-mmotm.orig/drivers/char/ip2/ip2main.c
+++ 2.6-mmotm/drivers/char/ip2/ip2main.c
@@ -252,7 +252,6 @@ static unsigned long bh_counter = 0;
*/
#define POLL_TIMEOUT (jiffies + 1)
static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
-static char TimerOn;
#ifdef IP2DEBUG_TRACE
/* Trace (debug) buffer data */
@@ -372,10 +371,7 @@ ip2_cleanup_module(void)
printk (KERN_DEBUG "Unloading %s: version %s\n", pcName, pcVersion );
#endif
/* 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 ) {
@@ -746,10 +742,8 @@ ip2_loadmain(int *iop, int *irqp)
}
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 {
@@ -1250,16 +1244,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 );
}
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ip2: avoid add_timer() with pending timer
2008-07-14 2:49 [PATCH] ip2: avoid add_timer() with pending timer Akinobu Mita
@ 2008-07-14 13:33 ` Alan Cox
2008-07-14 17:04 ` Andrew Morton
1 sibling, 0 replies; 4+ messages in thread
From: Alan Cox @ 2008-07-14 13:33 UTC (permalink / raw)
To: Akinobu Mita; +Cc: linux-kernel, Michael H. Warfield
On Mon, 14 Jul 2008 11:49:55 +0900
Akinobu Mita <akinobu.mita@gmail.com> wrote:
> 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>
> Cc: Michael H. Warfield <mhw@wittsend.com>
Acked-by: Alan Cox <alan@redhat.com>
Queued for ttydev tree
Alan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ip2: avoid add_timer() with pending timer
2008-07-14 2:49 [PATCH] ip2: avoid add_timer() with pending timer Akinobu Mita
2008-07-14 13:33 ` Alan Cox
@ 2008-07-14 17:04 ` Andrew Morton
2008-07-15 3:06 ` Akinobu Mita
1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2008-07-14 17:04 UTC (permalink / raw)
To: Akinobu Mita; +Cc: linux-kernel, Michael H. Warfield, Alan Cox
On Mon, 14 Jul 2008 11:49:55 +0900 Akinobu Mita <akinobu.mita@gmail.com> wrote:
> @@ -746,10 +742,8 @@ ip2_loadmain(int *iop, int *irqp)
> }
> 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");
This change to ip2_loadmain() might be racy if it actually did
anything. But afaict timer_pending() can never be true here (we're
only called from module_init()) so it can and should be removed.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ip2: avoid add_timer() with pending timer
2008-07-14 17:04 ` Andrew Morton
@ 2008-07-15 3:06 ` Akinobu Mita
0 siblings, 0 replies; 4+ messages in thread
From: Akinobu Mita @ 2008-07-15 3:06 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, Michael H. Warfield, Alan Cox
On Mon, Jul 14, 2008 at 10:04:02AM -0700, Andrew Morton wrote:
> On Mon, 14 Jul 2008 11:49:55 +0900 Akinobu Mita <akinobu.mita@gmail.com> wrote:
>
> > @@ -746,10 +742,8 @@ ip2_loadmain(int *iop, int *irqp)
> > }
> > 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");
>
> This change to ip2_loadmain() might be racy if it actually did
> anything. But afaict timer_pending() can never be true here (we're
> only called from module_init()) so it can and should be removed.
Yes, ip2_loadmain() is only called from module_init(). But this add_timer()
is in the loop for each device. So it may be called more than once.
And yes, I can remove timer_pending() here because I switched to use
mod_timer() instead of add_timer(). But this PollTimer works as periodic
timer and it's global timer. So it will not cause a problem.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-07-15 3:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-14 2:49 [PATCH] ip2: avoid add_timer() with pending timer Akinobu Mita
2008-07-14 13:33 ` Alan Cox
2008-07-14 17:04 ` Andrew Morton
2008-07-15 3:06 ` Akinobu Mita
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox