Selaa lähdekoodia

Char: moxa, serialise timer

- del timer after we are sure it won't be fired again
- make timer scheduling atomic
- don't reschedule timer when all cards have gone

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Tested-by: Oyvind Aabling <Oyvind.Aabling@uni-c.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Jiri Slaby 17 vuotta sitten
vanhempi
commit
2a5413416b
1 muutettua tiedostoa jossa 15 lisäystä ja 11 poistoa
  1. 15 11
      drivers/char/moxa.c

+ 15 - 11
drivers/char/moxa.c

@@ -846,10 +846,11 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
 	if (ret)
 	if (ret)
 		goto err_free;
 		goto err_free;
 
 
+	spin_lock_bh(&moxa_lock);
 	brd->ready = 1;
 	brd->ready = 1;
-
 	if (!timer_pending(&moxaTimer))
 	if (!timer_pending(&moxaTimer))
 		mod_timer(&moxaTimer, jiffies + HZ / 50);
 		mod_timer(&moxaTimer, jiffies + HZ / 50);
+	spin_unlock_bh(&moxa_lock);
 
 
 	return 0;
 	return 0;
 err_free:
 err_free:
@@ -1041,13 +1042,6 @@ static void __exit moxa_exit(void)
 {
 {
 	int i;
 	int i;
 
 
-	del_timer_sync(&moxaTimer);
-
-	if (tty_unregister_driver(moxaDriver))
-		printk(KERN_ERR "Couldn't unregister MOXA Intellio family "
-				"serial driver\n");
-	put_tty_driver(moxaDriver);
-
 #ifdef CONFIG_PCI
 #ifdef CONFIG_PCI
 	pci_unregister_driver(&moxa_pci_driver);
 	pci_unregister_driver(&moxa_pci_driver);
 #endif
 #endif
@@ -1055,6 +1049,13 @@ static void __exit moxa_exit(void)
 	for (i = 0; i < MAX_BOARDS; i++) /* ISA boards */
 	for (i = 0; i < MAX_BOARDS; i++) /* ISA boards */
 		if (moxa_boards[i].ready)
 		if (moxa_boards[i].ready)
 			moxa_board_deinit(&moxa_boards[i]);
 			moxa_board_deinit(&moxa_boards[i]);
+
+	del_timer_sync(&moxaTimer);
+
+	if (tty_unregister_driver(moxaDriver))
+		printk(KERN_ERR "Couldn't unregister MOXA Intellio family "
+				"serial driver\n");
+	put_tty_driver(moxaDriver);
 }
 }
 
 
 module_init(moxa_init);
 module_init(moxa_init);
@@ -1432,7 +1433,7 @@ static void moxa_poll(unsigned long ignored)
 {
 {
 	struct moxa_board_conf *brd;
 	struct moxa_board_conf *brd;
 	u16 __iomem *ip;
 	u16 __iomem *ip;
-	unsigned int card, port;
+	unsigned int card, port, served = 0;
 
 
 	spin_lock(&moxa_lock);
 	spin_lock(&moxa_lock);
 	for (card = 0; card < MAX_BOARDS; card++) {
 	for (card = 0; card < MAX_BOARDS; card++) {
@@ -1440,6 +1441,8 @@ static void moxa_poll(unsigned long ignored)
 		if (!brd->ready)
 		if (!brd->ready)
 			continue;
 			continue;
 
 
+		served++;
+
 		ip = NULL;
 		ip = NULL;
 		if (readb(brd->intPend) == 0xff)
 		if (readb(brd->intPend) == 0xff)
 			ip = brd->intTable + readb(brd->intNdx);
 			ip = brd->intTable + readb(brd->intNdx);
@@ -1460,9 +1463,10 @@ static void moxa_poll(unsigned long ignored)
 		}
 		}
 	}
 	}
 	moxaLowWaterChk = 0;
 	moxaLowWaterChk = 0;
-	spin_unlock(&moxa_lock);
 
 
-	mod_timer(&moxaTimer, jiffies + HZ / 50);
+	if (served)
+		mod_timer(&moxaTimer, jiffies + HZ / 50);
+	spin_unlock(&moxa_lock);
 }
 }
 
 
 /******************************************************************************/
 /******************************************************************************/