Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d020a2e authored by Akinobu Mita's avatar Akinobu Mita Committed by Linus Torvalds
Browse files

ip2: avoid add_timer with pending timer



add_timer() is not supposed 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: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: default avatarJiri Slaby <jirislaby@gmail.com>
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f1ddfd95
Loading
Loading
Loading
Loading
+4 −15
Original line number Original line Diff line number Diff line
@@ -249,7 +249,6 @@ static unsigned long bh_counter;
 */
 */
#define  POLL_TIMEOUT   (jiffies + 1)
#define  POLL_TIMEOUT   (jiffies + 1)
static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
static char  TimerOn;


#ifdef IP2DEBUG_TRACE
#ifdef IP2DEBUG_TRACE
/* Trace (debug) buffer data */
/* Trace (debug) buffer data */
@@ -374,11 +373,7 @@ static void __exit ip2_cleanup_module(void)
	int err;
	int err;
	int i;
	int i;


	/* Stop poll timer if we had one. */
	del_timer_sync(&PollTimer);
	if (TimerOn) {
		del_timer(&PollTimer);
		TimerOn = 0;
	}


	/* Reset the boards we have. */
	/* Reset the boards we have. */
	for (i = 0; i < IP2_MAX_BOARDS; i++)
	for (i = 0; i < IP2_MAX_BOARDS; i++)
@@ -774,10 +769,8 @@ static int __init ip2_loadmain(void)
		}
		}
		if (ip2config.irq[i] == CIR_POLL) {
		if (ip2config.irq[i] == CIR_POLL) {
retry:
retry:
			if (!TimerOn) {
			if (!timer_pending(&PollTimer)) {
				PollTimer.expires = POLL_TIMEOUT;
				mod_timer(&PollTimer, POLL_TIMEOUT);
				add_timer(&PollTimer);
				TimerOn = 1;
				printk(KERN_INFO "IP2: polling\n");
				printk(KERN_INFO "IP2: polling\n");
			}
			}
		} else {
		} else {
@@ -1283,16 +1276,12 @@ ip2_poll(unsigned long arg)
{
{
	ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 );
	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.
	// Just polled boards, IRQ = 0 will hit all non-interrupt boards.
	// It will NOT poll boards handled by hard interrupts.
	// It will NOT poll boards handled by hard interrupts.
	// The issue of queued BH interrupts is handled in ip2_interrupt().
	// The issue of queued BH interrupts is handled in ip2_interrupt().
	ip2_polled_interrupt();
	ip2_polled_interrupt();


	PollTimer.expires = POLL_TIMEOUT;
	mod_timer(&PollTimer, POLL_TIMEOUT);
	add_timer( &PollTimer );
	TimerOn = 1;


	ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
	ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
}
}