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

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

[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
Loading
Loading
Loading
Loading
+5 −9
Original line number Original line Diff line number Diff line
@@ -376,10 +376,8 @@ via_dmablit_handler(drm_device_t *dev, int engine, int from_irq)
			blitq->cur = cur;
			blitq->cur = cur;
			blitq->num_outstanding--;
			blitq->num_outstanding--;
			blitq->end = jiffies + DRM_HZ;
			blitq->end = jiffies + DRM_HZ;
			if (!timer_pending(&blitq->poll_timer)) {
			if (!timer_pending(&blitq->poll_timer))
				blitq->poll_timer.expires = jiffies+1;
				mod_timer(&blitq->poll_timer, jiffies + 1);
				add_timer(&blitq->poll_timer);
			}
		} else {
		} else {
			if (timer_pending(&blitq->poll_timer)) {
			if (timer_pending(&blitq->poll_timer)) {
				del_timer(&blitq->poll_timer);
				del_timer(&blitq->poll_timer);
@@ -478,8 +476,7 @@ via_dmablit_timer(unsigned long data)
	via_dmablit_handler(dev, engine, 0);
	via_dmablit_handler(dev, engine, 0);
	
	
	if (!timer_pending(&blitq->poll_timer)) {
	if (!timer_pending(&blitq->poll_timer)) {
		blitq->poll_timer.expires = jiffies+1;
		mod_timer(&blitq->poll_timer, jiffies + 1);
		add_timer(&blitq->poll_timer);


	       /*
	       /*
		* Rerun handler to delete timer if engines are off, and
		* 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);
		DRM_INIT_WAITQUEUE(&blitq->busy_queue);
		INIT_WORK(&blitq->wq, via_dmablit_workqueue);
		INIT_WORK(&blitq->wq, via_dmablit_workqueue);
		init_timer(&blitq->poll_timer);
		setup_timer(&blitq->poll_timer, via_dmablit_timer,
		blitq->poll_timer.function = &via_dmablit_timer;
				(unsigned long)blitq);
		blitq->poll_timer.data = (unsigned long) blitq;
	}	
	}	
}
}


+3 −5
Original line number Original line Diff line number Diff line
@@ -72,6 +72,7 @@
#define TRACE_RET ((void) 0)
#define TRACE_RET ((void) 0)
#endif				/* TRACING */
#endif				/* TRACING */


static void dtlk_timer_tick(unsigned long data);


static int dtlk_major;
static int dtlk_major;
static int dtlk_port_lpc;
static int dtlk_port_lpc;
@@ -81,7 +82,7 @@ static int dtlk_has_indexing;
static unsigned int dtlk_portlist[] =
static unsigned int dtlk_portlist[] =
{0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0};
{0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0};
static wait_queue_head_t dtlk_process_list;
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 */
/* prototypes for file_operations struct */
static ssize_t dtlk_read(struct file *, char __user *,
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_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,
static ssize_t dtlk_read(struct file *file, char __user *buf,
			 size_t count, loff_t * ppos)
			 size_t count, loff_t * ppos)
@@ -318,7 +318,7 @@ static int dtlk_release(struct inode *inode, struct file *file)
	}
	}
	TRACE_RET;
	TRACE_RET;
	
	
	del_timer(&dtlk_timer);
	del_timer_sync(&dtlk_timer);


	return 0;
	return 0;
}
}
@@ -336,8 +336,6 @@ static int __init dtlk_init(void)
	if (dtlk_dev_probe() == 0)
	if (dtlk_dev_probe() == 0)
		printk(", MAJOR %d\n", dtlk_major);
		printk(", MAJOR %d\n", dtlk_major);


	init_timer(&dtlk_timer);
	dtlk_timer.function = dtlk_timer_tick;
	init_waitqueue_head(&dtlk_process_list);
	init_waitqueue_head(&dtlk_process_list);


	return 0;
	return 0;
+17 −13
Original line number Original line Diff line number Diff line
@@ -80,7 +80,7 @@ static int i2RetryFlushOutput(i2ChanStrPtr);
// Not a documented part of the library routines (careful...) but the Diagnostic
// Not a documented part of the library routines (careful...) but the Diagnostic
// i2diag.c finds them useful to help the throughput in certain limited
// i2diag.c finds them useful to help the throughput in certain limited
// single-threaded operations.
// single-threaded operations.
static void iiSendPendingMail(i2eBordStrPtr);
static inline void iiSendPendingMail(i2eBordStrPtr);
static void serviceOutgoingFifo(i2eBordStrPtr);
static void serviceOutgoingFifo(i2eBordStrPtr);


// Functions defined in ip2.c as part of interrupt handling
// Functions defined in ip2.c as part of interrupt handling
@@ -150,6 +150,13 @@ i2Validate ( i2ChanStrPtr pCh )
			  == (CHANNEL_MAGIC | CHANNEL_SUPPORT));
			  == (CHANNEL_MAGIC | CHANNEL_SUPPORT));
}
}


static void iiSendPendingMail_t(unsigned long data)
{
	i2eBordStrPtr pB = (i2eBordStrPtr)data;

	iiSendPendingMail(pB);
}

//******************************************************************************
//******************************************************************************
// Function:   iiSendPendingMail(pB)
// Function:   iiSendPendingMail(pB)
// Parameters: Pointer to a board structure
// Parameters: Pointer to a board structure
@@ -184,12 +191,9 @@ iiSendPendingMail(i2eBordStrPtr pB)
			/\/\|=mhw=|\/\/				*/
			/\/\|=mhw=|\/\/				*/


			if( ++pB->SendPendingRetry < 16 ) {
			if( ++pB->SendPendingRetry < 16 ) {

				setup_timer(&pB->SendPendingTimer,
				init_timer( &(pB->SendPendingTimer) );
					iiSendPendingMail_t, (unsigned long)pB);
				pB->SendPendingTimer.expires  = jiffies + 1;
				mod_timer(&pB->SendPendingTimer, jiffies + 1);
				pB->SendPendingTimer.function = (void*)(unsigned long)iiSendPendingMail;
				pB->SendPendingTimer.data     = (unsigned long)pB;
				add_timer( &(pB->SendPendingTimer) );
			} else {
			} else {
				printk( KERN_ERR "IP2: iiSendPendingMail unable to queue outbound mail\n" );
				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.
// soon as all the data is completely sent.
//******************************************************************************
//******************************************************************************
static void
static void
i2DrainWakeup(i2ChanStrPtr pCh)
i2DrainWakeup(unsigned long d)
{
{
	i2ChanStrPtr pCh = (i2ChanStrPtr)d;

	ip2trace (CHANN, ITRC_DRAIN, 10, 1, pCh->BookmarkTimer.expires );
	ip2trace (CHANN, ITRC_DRAIN, 10, 1, pCh->BookmarkTimer.expires );


	pCh->BookmarkTimer.expires = 0;
	pCh->BookmarkTimer.expires = 0;
@@ -1292,14 +1298,12 @@ i2DrainOutput(i2ChanStrPtr pCh, int timeout)
	}
	}
	if ((timeout > 0) && (pCh->BookmarkTimer.expires == 0 )) {
	if ((timeout > 0) && (pCh->BookmarkTimer.expires == 0 )) {
		// One per customer (channel)
		// One per customer (channel)
		init_timer( &(pCh->BookmarkTimer) );
		setup_timer(&pCh->BookmarkTimer, i2DrainWakeup,
		pCh->BookmarkTimer.expires  = jiffies + timeout;
				(unsigned long)pCh);
		pCh->BookmarkTimer.function = (void*)(unsigned long)i2DrainWakeup;
		pCh->BookmarkTimer.data     = (unsigned long)pCh;


		ip2trace (CHANN, ITRC_DRAIN, 1, 1, pCh->BookmarkTimer.expires );
		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 );
	i2QueueCommands( PTYPE_INLINE, pCh, -1, 1, CMD_BMARK_REQ );
+1 −3
Original line number Original line Diff line number Diff line
@@ -1005,9 +1005,7 @@ static int r3964_open(struct tty_struct *tty)
	tty->disc_data = pInfo;
	tty->disc_data = pInfo;
	tty->receive_room = 65536;
	tty->receive_room = 65536;


	init_timer(&pInfo->tmr);
	setup_timer(&pInfo->tmr, on_timeout, (unsigned long)pInfo);
	pInfo->tmr.data = (unsigned long)pInfo;
	pInfo->tmr.function = on_timeout;


	return 0;
	return 0;
}
}
+5 −8
Original line number Original line Diff line number Diff line
@@ -23,8 +23,11 @@
#define __NWBUTTON_C		/* Tell the header file who we are */
#define __NWBUTTON_C		/* Tell the header file who we are */
#include "nwbutton.h"
#include "nwbutton.h"


static void button_sequence_finished (unsigned long parameters);

static int button_press_count;		/* The count of button presses */
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 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 char button_output_buffer[32];	/* Stores data to write out of device */
static int bcount;			/* The number of bytes in the buffer */
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)
static irqreturn_t button_handler (int irq, void *dev_id)
{
{
	if (button_press_count) {
		del_timer (&button_timer);
	}
	button_press_count++;
	button_press_count++;
	init_timer (&button_timer);
	mod_timer(&button_timer, jiffies + bdelay);
	button_timer.function = button_sequence_finished;
	button_timer.expires = (jiffies + bdelay);
	add_timer (&button_timer);


	return IRQ_HANDLED;
	return IRQ_HANDLED;
}
}
Loading