Commit 40565f19 authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds

[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: default avatarJiri 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d096f3e9
......@@ -376,10 +376,8 @@ via_dmablit_handler(drm_device_t *dev, int engine, int from_irq)
blitq->cur = cur;
blitq->num_outstanding--;
blitq->end = jiffies + DRM_HZ;
if (!timer_pending(&blitq->poll_timer)) {
blitq->poll_timer.expires = jiffies+1;
add_timer(&blitq->poll_timer);
}
if (!timer_pending(&blitq->poll_timer))
mod_timer(&blitq->poll_timer, jiffies + 1);
} else {
if (timer_pending(&blitq->poll_timer)) {
del_timer(&blitq->poll_timer);
......@@ -478,8 +476,7 @@ via_dmablit_timer(unsigned long data)
via_dmablit_handler(dev, engine, 0);
if (!timer_pending(&blitq->poll_timer)) {
blitq->poll_timer.expires = jiffies+1;
add_timer(&blitq->poll_timer);
mod_timer(&blitq->poll_timer, jiffies + 1);
/*
* Rerun handler to delete timer if engines are off, and
......@@ -574,9 +571,8 @@ via_init_dmablit(drm_device_t *dev)
}
DRM_INIT_WAITQUEUE(&blitq->busy_queue);
INIT_WORK(&blitq->wq, via_dmablit_workqueue);
init_timer(&blitq->poll_timer);
blitq->poll_timer.function = &via_dmablit_timer;
blitq->poll_timer.data = (unsigned long) blitq;
setup_timer(&blitq->poll_timer, via_dmablit_timer,
(unsigned long)blitq);
}
}
......
......@@ -72,6 +72,7 @@
#define TRACE_RET ((void) 0)
#endif /* TRACING */
static void dtlk_timer_tick(unsigned long data);
static int dtlk_major;
static int dtlk_port_lpc;
......@@ -81,7 +82,7 @@ static int dtlk_has_indexing;
static unsigned int dtlk_portlist[] =
{0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0};
static wait_queue_head_t dtlk_process_list;
static struct timer_list dtlk_timer;
static DEFINE_TIMER(dtlk_timer, dtlk_timer_tick, 0, 0);
/* prototypes for file_operations struct */
static ssize_t dtlk_read(struct file *, char __user *,
......@@ -117,7 +118,6 @@ static char dtlk_write_tts(char);
/*
static void dtlk_handle_error(char, char, unsigned int);
*/
static void dtlk_timer_tick(unsigned long data);
static ssize_t dtlk_read(struct file *file, char __user *buf,
size_t count, loff_t * ppos)
......@@ -318,7 +318,7 @@ static int dtlk_release(struct inode *inode, struct file *file)
}
TRACE_RET;
del_timer(&dtlk_timer);
del_timer_sync(&dtlk_timer);
return 0;
}
......@@ -336,8 +336,6 @@ static int __init dtlk_init(void)
if (dtlk_dev_probe() == 0)
printk(", MAJOR %d\n", dtlk_major);
init_timer(&dtlk_timer);
dtlk_timer.function = dtlk_timer_tick;
init_waitqueue_head(&dtlk_process_list);
return 0;
......
......@@ -80,7 +80,7 @@ static int i2RetryFlushOutput(i2ChanStrPtr);
// Not a documented part of the library routines (careful...) but the Diagnostic
// i2diag.c finds them useful to help the throughput in certain limited
// single-threaded operations.
static void iiSendPendingMail(i2eBordStrPtr);
static inline void iiSendPendingMail(i2eBordStrPtr);
static void serviceOutgoingFifo(i2eBordStrPtr);
// Functions defined in ip2.c as part of interrupt handling
......@@ -150,6 +150,13 @@ i2Validate ( i2ChanStrPtr pCh )
== (CHANNEL_MAGIC | CHANNEL_SUPPORT));
}
static void iiSendPendingMail_t(unsigned long data)
{
i2eBordStrPtr pB = (i2eBordStrPtr)data;
iiSendPendingMail(pB);
}
//******************************************************************************
// Function: iiSendPendingMail(pB)
// Parameters: Pointer to a board structure
......@@ -184,12 +191,9 @@ iiSendPendingMail(i2eBordStrPtr pB)
/\/\|=mhw=|\/\/ */
if( ++pB->SendPendingRetry < 16 ) {
init_timer( &(pB->SendPendingTimer) );
pB->SendPendingTimer.expires = jiffies + 1;
pB->SendPendingTimer.function = (void*)(unsigned long)iiSendPendingMail;
pB->SendPendingTimer.data = (unsigned long)pB;
add_timer( &(pB->SendPendingTimer) );
setup_timer(&pB->SendPendingTimer,
iiSendPendingMail_t, (unsigned long)pB);
mod_timer(&pB->SendPendingTimer, jiffies + 1);
} else {
printk( KERN_ERR "IP2: iiSendPendingMail unable to queue outbound mail\n" );
}
......@@ -1265,8 +1269,10 @@ i2RetryFlushOutput(i2ChanStrPtr pCh)
// soon as all the data is completely sent.
//******************************************************************************
static void
i2DrainWakeup(i2ChanStrPtr pCh)
i2DrainWakeup(unsigned long d)
{
i2ChanStrPtr pCh = (i2ChanStrPtr)d;
ip2trace (CHANN, ITRC_DRAIN, 10, 1, pCh->BookmarkTimer.expires );
pCh->BookmarkTimer.expires = 0;
......@@ -1292,14 +1298,12 @@ i2DrainOutput(i2ChanStrPtr pCh, int timeout)
}
if ((timeout > 0) && (pCh->BookmarkTimer.expires == 0 )) {
// One per customer (channel)
init_timer( &(pCh->BookmarkTimer) );
pCh->BookmarkTimer.expires = jiffies + timeout;
pCh->BookmarkTimer.function = (void*)(unsigned long)i2DrainWakeup;
pCh->BookmarkTimer.data = (unsigned long)pCh;
setup_timer(&pCh->BookmarkTimer, i2DrainWakeup,
(unsigned long)pCh);
ip2trace (CHANN, ITRC_DRAIN, 1, 1, pCh->BookmarkTimer.expires );
add_timer( &(pCh->BookmarkTimer) );
mod_timer(&pCh->BookmarkTimer, jiffies + timeout);
}
i2QueueCommands( PTYPE_INLINE, pCh, -1, 1, CMD_BMARK_REQ );
......
......@@ -1005,9 +1005,7 @@ static int r3964_open(struct tty_struct *tty)
tty->disc_data = pInfo;
tty->receive_room = 65536;
init_timer(&pInfo->tmr);
pInfo->tmr.data = (unsigned long)pInfo;
pInfo->tmr.function = on_timeout;
setup_timer(&pInfo->tmr, on_timeout, (unsigned long)pInfo);
return 0;
}
......
......@@ -23,8 +23,11 @@
#define __NWBUTTON_C /* Tell the header file who we are */
#include "nwbutton.h"
static void button_sequence_finished (unsigned long parameters);
static int button_press_count; /* The count of button presses */
static struct timer_list button_timer; /* Times for the end of a sequence */
/* Times for the end of a sequence */
static DEFINE_TIMER(button_timer, button_sequence_finished, 0, 0);
static DECLARE_WAIT_QUEUE_HEAD(button_wait_queue); /* Used for blocking read */
static char button_output_buffer[32]; /* Stores data to write out of device */
static int bcount; /* The number of bytes in the buffer */
......@@ -146,14 +149,8 @@ static void button_sequence_finished (unsigned long parameters)
static irqreturn_t button_handler (int irq, void *dev_id)
{
if (button_press_count) {
del_timer (&button_timer);
}
button_press_count++;
init_timer (&button_timer);
button_timer.function = button_sequence_finished;
button_timer.expires = (jiffies + bdelay);
add_timer (&button_timer);
mod_timer(&button_timer, jiffies + bdelay);
return IRQ_HANDLED;
}
......
......@@ -946,8 +946,7 @@ static void monitor_card(unsigned long p)
return_with_timer:
DEBUGP(7, dev, "<- monitor_card (returns with timer)\n");
dev->timer.expires = jiffies + dev->mdelay;
add_timer(&dev->timer);
mod_timer(&dev->timer, jiffies + dev->mdelay);
clear_bit(LOCK_MONITOR, &dev->flags);
}
......@@ -1406,12 +1405,9 @@ static void start_monitor(struct cm4000_dev *dev)
DEBUGP(3, dev, "-> start_monitor\n");
if (!dev->monitor_running) {
DEBUGP(5, dev, "create, init and add timer\n");
init_timer(&dev->timer);
setup_timer(&dev->timer, monitor_card, (unsigned long)dev);
dev->monitor_running = 1;
dev->timer.expires = jiffies;
dev->timer.data = (unsigned long) dev;
dev->timer.function = monitor_card;
add_timer(&dev->timer);
mod_timer(&dev->timer, jiffies);
} else
DEBUGP(5, dev, "monitor already running\n");
DEBUGP(3, dev, "<- start_monitor\n");
......
......@@ -632,8 +632,7 @@ static int reader_probe(struct pcmcia_device *link)
init_waitqueue_head(&dev->poll_wait);
init_waitqueue_head(&dev->read_wait);
init_waitqueue_head(&dev->write_wait);
init_timer(&dev->poll_timer);
dev->poll_timer.function = &cm4040_do_poll;
setup_timer(&dev->poll_timer, cm4040_do_poll, 0);
ret = reader_config(link, i);
if (ret)
......
......@@ -1361,9 +1361,7 @@ static int startup(MGSLPC_INFO * info)
memset(&info->icount, 0, sizeof(info->icount));
init_timer(&info->tx_timer);
info->tx_timer.data = (unsigned long)info;
info->tx_timer.function = tx_timeout;
setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info);
/* Allocate and claim adapter resources */
retval = claim_resources(info);
......@@ -1408,7 +1406,7 @@ static void shutdown(MGSLPC_INFO * info)
wake_up_interruptible(&info->status_event_wait_q);
wake_up_interruptible(&info->event_wait_q);
del_timer(&info->tx_timer);
del_timer_sync(&info->tx_timer);
if (info->tx_buf) {
free_page((unsigned long) info->tx_buf);
......@@ -3549,8 +3547,8 @@ static void tx_start(MGSLPC_INFO *info)
} else {
info->tx_active = 1;
tx_ready(info);
info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
add_timer(&info->tx_timer);
mod_timer(&info->tx_timer, jiffies +
msecs_to_jiffies(5000));
}
}
......
......@@ -418,8 +418,7 @@ static void rio_pollfunc(unsigned long data)
func_enter();
rio_interrupt(0, &p->RIOHosts[data]);
p->RIOHosts[data].timer.expires = jiffies + rio_poll;
add_timer(&p->RIOHosts[data].timer);
mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll);
func_exit();
}
......@@ -1154,13 +1153,10 @@ static int __init rio_init(void)
/* Init the timer "always" to make sure that it can safely be
deleted when we unload... */
init_timer(&hp->timer);
setup_timer(&hp->timer, rio_pollfunc, i);
if (!hp->Ivec) {
rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
hp->timer.data = i;
hp->timer.function = rio_pollfunc;
hp->timer.expires = jiffies + rio_poll;
add_timer(&hp->timer);
mod_timer(&hp->timer, jiffies + rio_poll);
}
}
......@@ -1191,7 +1187,7 @@ static void __exit rio_exit(void)
rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
}
/* It is safe/allowed to del_timer a non-active timer */
del_timer(&hp->timer);
del_timer_sync(&hp->timer);
if (hp->Caddr)
iounmap(hp->Caddr);
if (hp->Type == RIO_PCI)
......
......@@ -106,6 +106,8 @@
/****** RocketPort Local Variables ******/
static void rp_do_poll(unsigned long dummy);
static struct tty_driver *rocket_driver;
static struct rocket_version driver_version = {
......@@ -116,7 +118,7 @@ static struct r_port *rp_table[MAX_RP_PORTS]; /* The main repository of
static unsigned int xmit_flags[NUM_BOARDS]; /* Bit significant, indicates port had data to transmit. */
/* eg. Bit 0 indicates port 0 has xmit data, ... */
static atomic_t rp_num_ports_open; /* Number of serial ports open */
static struct timer_list rocket_timer;
static DEFINE_TIMER(rocket_timer, rp_do_poll, 0, 0);
static unsigned long board1; /* ISA addresses, retrieved from rocketport.conf */
static unsigned long board2;
......@@ -2367,12 +2369,6 @@ static int __init rp_init(void)
if (!rocket_driver)
return -ENOMEM;
/*
* Set up the timer channel.
*/
init_timer(&rocket_timer);
rocket_timer.function = rp_do_poll;
/*
* Initialize the array of pointers to our own internal state
* structures.
......
......@@ -135,7 +135,9 @@ static struct fasync_struct *rtc_async_queue;
static DECLARE_WAIT_QUEUE_HEAD(rtc_wait);
#ifdef RTC_IRQ
static struct timer_list rtc_irq_timer;
static void rtc_dropped_irq(unsigned long data);
static DEFINE_TIMER(rtc_irq_timer, rtc_dropped_irq, 0, 0);
#endif
static ssize_t rtc_read(struct file *file, char __user *buf,
......@@ -150,8 +152,6 @@ static unsigned int rtc_poll(struct file *file, poll_table *wait);
static void get_rtc_alm_time (struct rtc_time *alm_tm);
#ifdef RTC_IRQ
static void rtc_dropped_irq(unsigned long data);
static void set_rtc_irq_bit_locked(unsigned char bit);
static void mask_rtc_irq_bit_locked(unsigned char bit);
......@@ -454,8 +454,8 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
spin_lock_irqsave (&rtc_lock, flags);
if (!(rtc_status & RTC_TIMER_ON)) {
rtc_irq_timer.expires = jiffies + HZ/rtc_freq + 2*HZ/100;
add_timer(&rtc_irq_timer);
mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq +
2*HZ/100);
rtc_status |= RTC_TIMER_ON;
}
set_rtc_irq_bit_locked(RTC_PIE);
......@@ -1084,8 +1084,6 @@ static int __init rtc_init(void)
if (rtc_has_irq == 0)
goto no_irq2;
init_timer(&rtc_irq_timer);
rtc_irq_timer.function = rtc_dropped_irq;
spin_lock_irq(&rtc_lock);
rtc_freq = 1024;
if (!hpet_set_periodic_freq(rtc_freq)) {
......
......@@ -461,8 +461,7 @@ void missed_irq (unsigned long data)
sx_interrupt (((struct specialix_board *)data)->irq,
(void*)data);
}
missed_irq_timer.expires = jiffies + sx_poll;
add_timer (&missed_irq_timer);
mod_timer(&missed_irq_timer, jiffies + sx_poll);
}
#endif
......@@ -597,11 +596,8 @@ static int sx_probe(struct specialix_board *bp)
dprintk (SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) );
#ifdef SPECIALIX_TIMER
init_timer (&missed_irq_timer);
missed_irq_timer.function = missed_irq;
missed_irq_timer.data = (unsigned long) bp;
missed_irq_timer.expires = jiffies + sx_poll;
add_timer (&missed_irq_timer);
setup_timer(&missed_irq_timer, missed_irq, (unsigned long)bp);
mod_timer(&missed_irq_timer, jiffies + sx_poll);
#endif
printk(KERN_INFO"sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n",
......@@ -2559,7 +2555,7 @@ static void __exit specialix_exit_module(void)
if (sx_board[i].flags & SX_BOARD_PRESENT)
sx_release_io_range(&sx_board[i]);
#ifdef SPECIALIX_TIMER
del_timer (&missed_irq_timer);
del_timer_sync(&missed_irq_timer);
#endif
func_exit();
......
......@@ -1798,9 +1798,7 @@ static int startup(struct mgsl_struct * info)
memset(&info->icount, 0, sizeof(info->icount));
init_timer(&info->tx_timer);
info->tx_timer.data = (unsigned long)info;
info->tx_timer.function = mgsl_tx_timeout;
setup_timer(&info->tx_timer, mgsl_tx_timeout, (unsigned long)info);
/* Allocate and claim adapter resources */
retval = mgsl_claim_resources(info);
......@@ -1851,7 +1849,7 @@ static void shutdown(struct mgsl_struct * info)
wake_up_interruptible(&info->status_event_wait_q);
wake_up_interruptible(&info->event_wait_q);
del_timer(&info->tx_timer);
del_timer_sync(&info->tx_timer);
if (info->xmit_buf) {
free_page((unsigned long) info->xmit_buf);
......@@ -5710,8 +5708,8 @@ static void usc_start_transmitter( struct mgsl_struct *info )
usc_TCmd( info, TCmd_SendFrame );
info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
add_timer(&info->tx_timer);
mod_timer(&info->tx_timer, jiffies +
msecs_to_jiffies(5000));
}
info->tx_active = 1;
}
......
......@@ -1825,8 +1825,7 @@ static void rx_async(struct slgt_info *info)
if (i < count) {
/* receive buffer not completed */
info->rbuf_index += i;
info->rx_timer.expires = jiffies + 1;
add_timer(&info->rx_timer);
mod_timer(&info->rx_timer, jiffies + 1);
break;
}
......@@ -3340,13 +3339,8 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev
info->adapter_num = adapter_num;
info->port_num = port_num;
init_timer(&info->tx_timer);
info->tx_timer.data = (unsigned long)info;
info->tx_timer.function = tx_timeout;
init_timer(&info->rx_timer);
info->rx_timer.data = (unsigned long)info;
info->rx_timer.function = rx_timeout;
setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info);
setup_timer(&info->rx_timer, rx_timeout, (unsigned long)info);
/* Copy configuration info to device instance data */
info->pdev = pdev;
......@@ -3794,10 +3788,9 @@ static void tx_start(struct slgt_info *info)
}
}
if (info->params.mode == MGSL_MODE_HDLC) {
info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
add_timer(&info->tx_timer);
}
if (info->params.mode == MGSL_MODE_HDLC)
mod_timer(&info->tx_timer, jiffies +
msecs_to_jiffies(5000));
} else {
tdma_reset(info);
/* set 1st descriptor address */
......
......@@ -2744,8 +2744,7 @@ static int startup(SLMP_INFO * info)
change_params(info);
info->status_timer.expires = jiffies + msecs_to_jiffies(10);
add_timer(&info->status_timer);
mod_timer(&info->status_timer, jiffies + msecs_to_jiffies(10));
if (info->tty)
clear_bit(TTY_IO_ERROR, &info->tty->flags);
......@@ -3841,13 +3840,9 @@ static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
info->bus_type = MGSL_BUS_TYPE_PCI;
info->irq_flags = IRQF_SHARED;
init_timer(&info->tx_timer);
info->tx_timer.data = (unsigned long)info;
info->tx_timer.function = tx_timeout;
init_timer(&info->status_timer);
info->status_timer.data = (unsigned long)info;
info->status_timer.function = status_timeout;
setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info);
setup_timer(&info->status_timer, status_timeout,
(unsigned long)info);
/* Store the PCI9050 misc control register value because a flaw
* in the PCI9050 prevents LCR registers from being read if
......@@ -4291,8 +4286,8 @@ void tx_start(SLMP_INFO *info)
write_reg(info, TXDMA + DIR, 0x40); /* enable Tx DMA interrupts (EOM) */
write_reg(info, TXDMA + DSR, 0xf2); /* clear Tx DMA IRQs, enable Tx DMA */
info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
add_timer(&info->tx_timer);
mod_timer(&info->tx_timer, jiffies +
msecs_to_jiffies(5000));
}
else {
tx_load_fifo(info);
......@@ -5574,10 +5569,7 @@ void status_timeout(unsigned long context)
if (status)
isr_io_pin(info,status);
info->status_timer.data = (unsigned long)info;
info->status_timer.function = status_timeout;
info->status_timer.expires = jiffies + msecs_to_jiffies(10);
add_timer(&info->status_timer);
mod_timer(&info->status_timer, jiffies + msecs_to_jiffies(10));
}
......
......@@ -1107,9 +1107,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
INIT_WORK(&chip->work, timeout_work);
init_timer(&chip->user_read_timer);
chip->user_read_timer.function = user_reader_timeout;
chip->user_read_timer.data = (unsigned long) chip;
setup_timer(&chip->user_read_timer, user_reader_timeout,
(unsigned long)chip);
memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific));
......
......@@ -210,7 +210,7 @@ static int scrollback_delta;
*/
int (*console_blank_hook)(int);
static struct timer_list console_timer;
static DEFINE_TIMER(console_timer, blank_screen_t, 0, 0);
static int blank_state;
static int blank_timer_expired;
enum {
......@@ -2625,8 +2625,6 @@ static int __init con_init(void)
for (i = 0; i < MAX_NR_CONSOLES; i++)
con_driver_map[i] = conswitchp;
init_timer(&console_timer);
console_timer.function = blank_screen_t;
if (blankinterval) {
blank_state = blank_normal_wait;
mod_timer(&console_timer, jiffies + blankinterval);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment