Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] Char: timers cleanup

- Use timer macros to set function and data members and to modify
expiration time.
- Use DEFINE_TIMER for global timers and do not init them at run-time in
these cases.
- del_timer_sync is common in most cases -- we want to wait for timer
function if it's still running.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Paul Fulghum <paulkf@microgate.com>
Cc: Kylene Jo Hall <kjhall@us.ibm.com>
Cc: Wim Van Sebroeck <wim@iguana.be>
Acked-by: Dmitry Torokhov <dtor@mail.ru> (Input bits)
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Jiri Slaby and committed by
Linus Torvalds
40565f19 d096f3e9

+75 -123
+5 -9
drivers/char/drm/via_dmablit.c
··· 376 376 blitq->cur = cur; 377 377 blitq->num_outstanding--; 378 378 blitq->end = jiffies + DRM_HZ; 379 - if (!timer_pending(&blitq->poll_timer)) { 380 - blitq->poll_timer.expires = jiffies+1; 381 - add_timer(&blitq->poll_timer); 382 - } 379 + if (!timer_pending(&blitq->poll_timer)) 380 + mod_timer(&blitq->poll_timer, jiffies + 1); 383 381 } else { 384 382 if (timer_pending(&blitq->poll_timer)) { 385 383 del_timer(&blitq->poll_timer); ··· 476 478 via_dmablit_handler(dev, engine, 0); 477 479 478 480 if (!timer_pending(&blitq->poll_timer)) { 479 - blitq->poll_timer.expires = jiffies+1; 480 - add_timer(&blitq->poll_timer); 481 + mod_timer(&blitq->poll_timer, jiffies + 1); 481 482 482 483 /* 483 484 * Rerun handler to delete timer if engines are off, and ··· 571 574 } 572 575 DRM_INIT_WAITQUEUE(&blitq->busy_queue); 573 576 INIT_WORK(&blitq->wq, via_dmablit_workqueue); 574 - init_timer(&blitq->poll_timer); 575 - blitq->poll_timer.function = &via_dmablit_timer; 576 - blitq->poll_timer.data = (unsigned long) blitq; 577 + setup_timer(&blitq->poll_timer, via_dmablit_timer, 578 + (unsigned long)blitq); 577 579 } 578 580 } 579 581
+3 -5
drivers/char/dtlk.c
··· 72 72 #define TRACE_RET ((void) 0) 73 73 #endif /* TRACING */ 74 74 75 + static void dtlk_timer_tick(unsigned long data); 75 76 76 77 static int dtlk_major; 77 78 static int dtlk_port_lpc; ··· 82 81 static unsigned int dtlk_portlist[] = 83 82 {0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0}; 84 83 static wait_queue_head_t dtlk_process_list; 85 - static struct timer_list dtlk_timer; 84 + static DEFINE_TIMER(dtlk_timer, dtlk_timer_tick, 0, 0); 86 85 87 86 /* prototypes for file_operations struct */ 88 87 static ssize_t dtlk_read(struct file *, char __user *, ··· 118 117 /* 119 118 static void dtlk_handle_error(char, char, unsigned int); 120 119 */ 121 - static void dtlk_timer_tick(unsigned long data); 122 120 123 121 static ssize_t dtlk_read(struct file *file, char __user *buf, 124 122 size_t count, loff_t * ppos) ··· 318 318 } 319 319 TRACE_RET; 320 320 321 - del_timer(&dtlk_timer); 321 + del_timer_sync(&dtlk_timer); 322 322 323 323 return 0; 324 324 } ··· 336 336 if (dtlk_dev_probe() == 0) 337 337 printk(", MAJOR %d\n", dtlk_major); 338 338 339 - init_timer(&dtlk_timer); 340 - dtlk_timer.function = dtlk_timer_tick; 341 339 init_waitqueue_head(&dtlk_process_list); 342 340 343 341 return 0;
+17 -13
drivers/char/ip2/i2lib.c
··· 80 80 // Not a documented part of the library routines (careful...) but the Diagnostic 81 81 // i2diag.c finds them useful to help the throughput in certain limited 82 82 // single-threaded operations. 83 - static void iiSendPendingMail(i2eBordStrPtr); 83 + static inline void iiSendPendingMail(i2eBordStrPtr); 84 84 static void serviceOutgoingFifo(i2eBordStrPtr); 85 85 86 86 // Functions defined in ip2.c as part of interrupt handling ··· 150 150 == (CHANNEL_MAGIC | CHANNEL_SUPPORT)); 151 151 } 152 152 153 + static void iiSendPendingMail_t(unsigned long data) 154 + { 155 + i2eBordStrPtr pB = (i2eBordStrPtr)data; 156 + 157 + iiSendPendingMail(pB); 158 + } 159 + 153 160 //****************************************************************************** 154 161 // Function: iiSendPendingMail(pB) 155 162 // Parameters: Pointer to a board structure ··· 191 184 /\/\|=mhw=|\/\/ */ 192 185 193 186 if( ++pB->SendPendingRetry < 16 ) { 194 - 195 - init_timer( &(pB->SendPendingTimer) ); 196 - pB->SendPendingTimer.expires = jiffies + 1; 197 - pB->SendPendingTimer.function = (void*)(unsigned long)iiSendPendingMail; 198 - pB->SendPendingTimer.data = (unsigned long)pB; 199 - add_timer( &(pB->SendPendingTimer) ); 187 + setup_timer(&pB->SendPendingTimer, 188 + iiSendPendingMail_t, (unsigned long)pB); 189 + mod_timer(&pB->SendPendingTimer, jiffies + 1); 200 190 } else { 201 191 printk( KERN_ERR "IP2: iiSendPendingMail unable to queue outbound mail\n" ); 202 192 } ··· 1269 1265 // soon as all the data is completely sent. 1270 1266 //****************************************************************************** 1271 1267 static void 1272 - i2DrainWakeup(i2ChanStrPtr pCh) 1268 + i2DrainWakeup(unsigned long d) 1273 1269 { 1270 + i2ChanStrPtr pCh = (i2ChanStrPtr)d; 1271 + 1274 1272 ip2trace (CHANN, ITRC_DRAIN, 10, 1, pCh->BookmarkTimer.expires ); 1275 1273 1276 1274 pCh->BookmarkTimer.expires = 0; ··· 1298 1292 } 1299 1293 if ((timeout > 0) && (pCh->BookmarkTimer.expires == 0 )) { 1300 1294 // One per customer (channel) 1301 - init_timer( &(pCh->BookmarkTimer) ); 1302 - pCh->BookmarkTimer.expires = jiffies + timeout; 1303 - pCh->BookmarkTimer.function = (void*)(unsigned long)i2DrainWakeup; 1304 - pCh->BookmarkTimer.data = (unsigned long)pCh; 1295 + setup_timer(&pCh->BookmarkTimer, i2DrainWakeup, 1296 + (unsigned long)pCh); 1305 1297 1306 1298 ip2trace (CHANN, ITRC_DRAIN, 1, 1, pCh->BookmarkTimer.expires ); 1307 1299 1308 - add_timer( &(pCh->BookmarkTimer) ); 1300 + mod_timer(&pCh->BookmarkTimer, jiffies + timeout); 1309 1301 } 1310 1302 1311 1303 i2QueueCommands( PTYPE_INLINE, pCh, -1, 1, CMD_BMARK_REQ );
+1 -3
drivers/char/n_r3964.c
··· 1005 1005 tty->disc_data = pInfo; 1006 1006 tty->receive_room = 65536; 1007 1007 1008 - init_timer(&pInfo->tmr); 1009 - pInfo->tmr.data = (unsigned long)pInfo; 1010 - pInfo->tmr.function = on_timeout; 1008 + setup_timer(&pInfo->tmr, on_timeout, (unsigned long)pInfo); 1011 1009 1012 1010 return 0; 1013 1011 }
+5 -8
drivers/char/nwbutton.c
··· 23 23 #define __NWBUTTON_C /* Tell the header file who we are */ 24 24 #include "nwbutton.h" 25 25 26 + static void button_sequence_finished (unsigned long parameters); 27 + 26 28 static int button_press_count; /* The count of button presses */ 27 - static struct timer_list button_timer; /* Times for the end of a sequence */ 29 + /* Times for the end of a sequence */ 30 + static DEFINE_TIMER(button_timer, button_sequence_finished, 0, 0); 28 31 static DECLARE_WAIT_QUEUE_HEAD(button_wait_queue); /* Used for blocking read */ 29 32 static char button_output_buffer[32]; /* Stores data to write out of device */ 30 33 static int bcount; /* The number of bytes in the buffer */ ··· 149 146 150 147 static irqreturn_t button_handler (int irq, void *dev_id) 151 148 { 152 - if (button_press_count) { 153 - del_timer (&button_timer); 154 - } 155 149 button_press_count++; 156 - init_timer (&button_timer); 157 - button_timer.function = button_sequence_finished; 158 - button_timer.expires = (jiffies + bdelay); 159 - add_timer (&button_timer); 150 + mod_timer(&button_timer, jiffies + bdelay); 160 151 161 152 return IRQ_HANDLED; 162 153 }
+3 -7
drivers/char/pcmcia/cm4000_cs.c
··· 946 946 947 947 return_with_timer: 948 948 DEBUGP(7, dev, "<- monitor_card (returns with timer)\n"); 949 - dev->timer.expires = jiffies + dev->mdelay; 950 - add_timer(&dev->timer); 949 + mod_timer(&dev->timer, jiffies + dev->mdelay); 951 950 clear_bit(LOCK_MONITOR, &dev->flags); 952 951 } 953 952 ··· 1405 1406 DEBUGP(3, dev, "-> start_monitor\n"); 1406 1407 if (!dev->monitor_running) { 1407 1408 DEBUGP(5, dev, "create, init and add timer\n"); 1408 - init_timer(&dev->timer); 1409 + setup_timer(&dev->timer, monitor_card, (unsigned long)dev); 1409 1410 dev->monitor_running = 1; 1410 - dev->timer.expires = jiffies; 1411 - dev->timer.data = (unsigned long) dev; 1412 - dev->timer.function = monitor_card; 1413 - add_timer(&dev->timer); 1411 + mod_timer(&dev->timer, jiffies); 1414 1412 } else 1415 1413 DEBUGP(5, dev, "monitor already running\n"); 1416 1414 DEBUGP(3, dev, "<- start_monitor\n");
+1 -2
drivers/char/pcmcia/cm4040_cs.c
··· 632 632 init_waitqueue_head(&dev->poll_wait); 633 633 init_waitqueue_head(&dev->read_wait); 634 634 init_waitqueue_head(&dev->write_wait); 635 - init_timer(&dev->poll_timer); 636 - dev->poll_timer.function = &cm4040_do_poll; 635 + setup_timer(&dev->poll_timer, cm4040_do_poll, 0); 637 636 638 637 ret = reader_config(link, i); 639 638 if (ret)
+4 -8
drivers/char/rio/rio_linux.c
··· 418 418 func_enter(); 419 419 420 420 rio_interrupt(0, &p->RIOHosts[data]); 421 - p->RIOHosts[data].timer.expires = jiffies + rio_poll; 422 - add_timer(&p->RIOHosts[data].timer); 421 + mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll); 423 422 424 423 func_exit(); 425 424 } ··· 1153 1154 /* Init the timer "always" to make sure that it can safely be 1154 1155 deleted when we unload... */ 1155 1156 1156 - init_timer(&hp->timer); 1157 + setup_timer(&hp->timer, rio_pollfunc, i); 1157 1158 if (!hp->Ivec) { 1158 1159 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll); 1159 - hp->timer.data = i; 1160 - hp->timer.function = rio_pollfunc; 1161 - hp->timer.expires = jiffies + rio_poll; 1162 - add_timer(&hp->timer); 1160 + mod_timer(&hp->timer, jiffies + rio_poll); 1163 1161 } 1164 1162 } 1165 1163 ··· 1187 1191 rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec); 1188 1192 } 1189 1193 /* It is safe/allowed to del_timer a non-active timer */ 1190 - del_timer(&hp->timer); 1194 + del_timer_sync(&hp->timer); 1191 1195 if (hp->Caddr) 1192 1196 iounmap(hp->Caddr); 1193 1197 if (hp->Type == RIO_PCI)
+3 -7
drivers/char/rocket.c
··· 106 106 107 107 /****** RocketPort Local Variables ******/ 108 108 109 + static void rp_do_poll(unsigned long dummy); 110 + 109 111 static struct tty_driver *rocket_driver; 110 112 111 113 static struct rocket_version driver_version = { ··· 118 116 static unsigned int xmit_flags[NUM_BOARDS]; /* Bit significant, indicates port had data to transmit. */ 119 117 /* eg. Bit 0 indicates port 0 has xmit data, ... */ 120 118 static atomic_t rp_num_ports_open; /* Number of serial ports open */ 121 - static struct timer_list rocket_timer; 119 + static DEFINE_TIMER(rocket_timer, rp_do_poll, 0, 0); 122 120 123 121 static unsigned long board1; /* ISA addresses, retrieved from rocketport.conf */ 124 122 static unsigned long board2; ··· 2368 2366 rocket_driver = alloc_tty_driver(MAX_RP_PORTS); 2369 2367 if (!rocket_driver) 2370 2368 return -ENOMEM; 2371 - 2372 - /* 2373 - * Set up the timer channel. 2374 - */ 2375 - init_timer(&rocket_timer); 2376 - rocket_timer.function = rp_do_poll; 2377 2369 2378 2370 /* 2379 2371 * Initialize the array of pointers to our own internal state
+5 -7
drivers/char/rtc.c
··· 135 135 static DECLARE_WAIT_QUEUE_HEAD(rtc_wait); 136 136 137 137 #ifdef RTC_IRQ 138 - static struct timer_list rtc_irq_timer; 138 + static void rtc_dropped_irq(unsigned long data); 139 + 140 + static DEFINE_TIMER(rtc_irq_timer, rtc_dropped_irq, 0, 0); 139 141 #endif 140 142 141 143 static ssize_t rtc_read(struct file *file, char __user *buf, ··· 152 150 153 151 static void get_rtc_alm_time (struct rtc_time *alm_tm); 154 152 #ifdef RTC_IRQ 155 - static void rtc_dropped_irq(unsigned long data); 156 - 157 153 static void set_rtc_irq_bit_locked(unsigned char bit); 158 154 static void mask_rtc_irq_bit_locked(unsigned char bit); 159 155 ··· 454 454 455 455 spin_lock_irqsave (&rtc_lock, flags); 456 456 if (!(rtc_status & RTC_TIMER_ON)) { 457 - rtc_irq_timer.expires = jiffies + HZ/rtc_freq + 2*HZ/100; 458 - add_timer(&rtc_irq_timer); 457 + mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq + 458 + 2*HZ/100); 459 459 rtc_status |= RTC_TIMER_ON; 460 460 } 461 461 set_rtc_irq_bit_locked(RTC_PIE); ··· 1084 1084 if (rtc_has_irq == 0) 1085 1085 goto no_irq2; 1086 1086 1087 - init_timer(&rtc_irq_timer); 1088 - rtc_irq_timer.function = rtc_dropped_irq; 1089 1087 spin_lock_irq(&rtc_lock); 1090 1088 rtc_freq = 1024; 1091 1089 if (!hpet_set_periodic_freq(rtc_freq)) {
+4 -8
drivers/char/specialix.c
··· 461 461 sx_interrupt (((struct specialix_board *)data)->irq, 462 462 (void*)data); 463 463 } 464 - missed_irq_timer.expires = jiffies + sx_poll; 465 - add_timer (&missed_irq_timer); 464 + mod_timer(&missed_irq_timer, jiffies + sx_poll); 466 465 } 467 466 #endif 468 467 ··· 596 597 dprintk (SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) ); 597 598 598 599 #ifdef SPECIALIX_TIMER 599 - init_timer (&missed_irq_timer); 600 - missed_irq_timer.function = missed_irq; 601 - missed_irq_timer.data = (unsigned long) bp; 602 - missed_irq_timer.expires = jiffies + sx_poll; 603 - add_timer (&missed_irq_timer); 600 + setup_timer(&missed_irq_timer, missed_irq, (unsigned long)bp); 601 + mod_timer(&missed_irq_timer, jiffies + sx_poll); 604 602 #endif 605 603 606 604 printk(KERN_INFO"sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n", ··· 2555 2559 if (sx_board[i].flags & SX_BOARD_PRESENT) 2556 2560 sx_release_io_range(&sx_board[i]); 2557 2561 #ifdef SPECIALIX_TIMER 2558 - del_timer (&missed_irq_timer); 2562 + del_timer_sync(&missed_irq_timer); 2559 2563 #endif 2560 2564 2561 2565 func_exit();
+4 -6
drivers/char/synclink.c
··· 1798 1798 1799 1799 memset(&info->icount, 0, sizeof(info->icount)); 1800 1800 1801 - init_timer(&info->tx_timer); 1802 - info->tx_timer.data = (unsigned long)info; 1803 - info->tx_timer.function = mgsl_tx_timeout; 1801 + setup_timer(&info->tx_timer, mgsl_tx_timeout, (unsigned long)info); 1804 1802 1805 1803 /* Allocate and claim adapter resources */ 1806 1804 retval = mgsl_claim_resources(info); ··· 1849 1851 wake_up_interruptible(&info->status_event_wait_q); 1850 1852 wake_up_interruptible(&info->event_wait_q); 1851 1853 1852 - del_timer(&info->tx_timer); 1854 + del_timer_sync(&info->tx_timer); 1853 1855 1854 1856 if (info->xmit_buf) { 1855 1857 free_page((unsigned long) info->xmit_buf); ··· 5708 5710 5709 5711 usc_TCmd( info, TCmd_SendFrame ); 5710 5712 5711 - info->tx_timer.expires = jiffies + msecs_to_jiffies(5000); 5712 - add_timer(&info->tx_timer); 5713 + mod_timer(&info->tx_timer, jiffies + 5714 + msecs_to_jiffies(5000)); 5713 5715 } 5714 5716 info->tx_active = 1; 5715 5717 }
+7 -15
drivers/char/synclinkmp.c
··· 2744 2744 2745 2745 change_params(info); 2746 2746 2747 - info->status_timer.expires = jiffies + msecs_to_jiffies(10); 2748 - add_timer(&info->status_timer); 2747 + mod_timer(&info->status_timer, jiffies + msecs_to_jiffies(10)); 2749 2748 2750 2749 if (info->tty) 2751 2750 clear_bit(TTY_IO_ERROR, &info->tty->flags); ··· 3840 3841 info->bus_type = MGSL_BUS_TYPE_PCI; 3841 3842 info->irq_flags = IRQF_SHARED; 3842 3843 3843 - init_timer(&info->tx_timer); 3844 - info->tx_timer.data = (unsigned long)info; 3845 - info->tx_timer.function = tx_timeout; 3846 - 3847 - init_timer(&info->status_timer); 3848 - info->status_timer.data = (unsigned long)info; 3849 - info->status_timer.function = status_timeout; 3844 + setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info); 3845 + setup_timer(&info->status_timer, status_timeout, 3846 + (unsigned long)info); 3850 3847 3851 3848 /* Store the PCI9050 misc control register value because a flaw 3852 3849 * in the PCI9050 prevents LCR registers from being read if ··· 4286 4291 write_reg(info, TXDMA + DIR, 0x40); /* enable Tx DMA interrupts (EOM) */ 4287 4292 write_reg(info, TXDMA + DSR, 0xf2); /* clear Tx DMA IRQs, enable Tx DMA */ 4288 4293 4289 - info->tx_timer.expires = jiffies + msecs_to_jiffies(5000); 4290 - add_timer(&info->tx_timer); 4294 + mod_timer(&info->tx_timer, jiffies + 4295 + msecs_to_jiffies(5000)); 4291 4296 } 4292 4297 else { 4293 4298 tx_load_fifo(info); ··· 5569 5574 if (status) 5570 5575 isr_io_pin(info,status); 5571 5576 5572 - info->status_timer.data = (unsigned long)info; 5573 - info->status_timer.function = status_timeout; 5574 - info->status_timer.expires = jiffies + msecs_to_jiffies(10); 5575 - add_timer(&info->status_timer); 5577 + mod_timer(&info->status_timer, jiffies + msecs_to_jiffies(10)); 5576 5578 } 5577 5579 5578 5580
+2 -3
drivers/char/tpm/tpm.c
··· 1107 1107 1108 1108 INIT_WORK(&chip->work, timeout_work); 1109 1109 1110 - init_timer(&chip->user_read_timer); 1111 - chip->user_read_timer.function = user_reader_timeout; 1112 - chip->user_read_timer.data = (unsigned long) chip; 1110 + setup_timer(&chip->user_read_timer, user_reader_timeout, 1111 + (unsigned long)chip); 1113 1112 1114 1113 memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific)); 1115 1114
+1 -3
drivers/char/vt.c
··· 210 210 */ 211 211 int (*console_blank_hook)(int); 212 212 213 - static struct timer_list console_timer; 213 + static DEFINE_TIMER(console_timer, blank_screen_t, 0, 0); 214 214 static int blank_state; 215 215 static int blank_timer_expired; 216 216 enum { ··· 2625 2625 for (i = 0; i < MAX_NR_CONSOLES; i++) 2626 2626 con_driver_map[i] = conswitchp; 2627 2627 2628 - init_timer(&console_timer); 2629 - console_timer.function = blank_screen_t; 2630 2628 if (blankinterval) { 2631 2629 blank_state = blank_normal_wait; 2632 2630 mod_timer(&console_timer, jiffies + blankinterval);