All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/8] Char: mxser_new, fix sparse warning
@ 2007-05-28 13:26 Jiri Slaby
  2007-05-28 13:27 ` [PATCH 2/8] Char: tty_ioctl, use wait_event_interruptible_timeout Jiri Slaby
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Jiri Slaby @ 2007-05-28 13:26 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

mxser_new, fix sparse warning

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit 29f15033f00e36f622d0bcd5a2dd0f9a49981481
tree 2a332865460a2775256b5087f8da6ff8f1befdf0
parent 1f023432798b6e6fd52ad81af0eab250e1a71449
author Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 18:14:21 +0200
committer Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 18:14:21 +0200

 drivers/char/mxser_new.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/char/mxser_new.c b/drivers/char/mxser_new.c
index 6cde448..71b9657 100644
--- a/drivers/char/mxser_new.c
+++ b/drivers/char/mxser_new.c
@@ -1560,7 +1560,7 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
 			return -EFAULT;
 		return 0;
 	case MOXA_ASPP_MON_EXT: {
-		int status, p, shiftbit;
+		int p, shiftbit;
 		unsigned long opmode;
 		unsigned cflag, iflag;
 

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/8] Char: tty_ioctl, use wait_event_interruptible_timeout
  2007-05-28 13:26 [PATCH 1/8] Char: mxser_new, fix sparse warning Jiri Slaby
@ 2007-05-28 13:27 ` Jiri Slaby
  2007-05-28 13:27 ` [PATCH 3/8] Char: tty_ioctl, little whitespace cleanup Jiri Slaby
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Jiri Slaby @ 2007-05-28 13:27 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Alan Cox

tty_ioctl, use wait_event_interruptible_timeout

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>

---
commit f030662cbc20e758047c5ec07396862761ea8643
tree 113645cd1e51b8469b77022f2c68fdb94ab54449
parent 29f15033f00e36f622d0bcd5a2dd0f9a49981481
author Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 20:56:41 +0200
committer Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 20:56:41 +0200

 drivers/char/tty_ioctl.c |   21 +++------------------
 1 files changed, 3 insertions(+), 18 deletions(-)

diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 918e24c..2b6a384 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -52,8 +52,6 @@
 
 void tty_wait_until_sent(struct tty_struct * tty, long timeout)
 {
-	DECLARE_WAITQUEUE(wait, current);
-
 #ifdef TTY_DEBUG_WAIT_UNTIL_SENT
 	char buf[64];
 	
@@ -61,26 +59,13 @@ void tty_wait_until_sent(struct tty_struct * tty, long timeout)
 #endif
 	if (!tty->driver->chars_in_buffer)
 		return;
-	add_wait_queue(&tty->write_wait, &wait);
 	if (!timeout)
 		timeout = MAX_SCHEDULE_TIMEOUT;
-	do {
-#ifdef TTY_DEBUG_WAIT_UNTIL_SENT
-		printk(KERN_DEBUG "waiting %s...(%d)\n", tty_name(tty, buf),
-		       tty->driver->chars_in_buffer(tty));
-#endif
-		set_current_state(TASK_INTERRUPTIBLE);
-		if (signal_pending(current))
-			goto stop_waiting;
-		if (!tty->driver->chars_in_buffer(tty))
-			break;
-		timeout = schedule_timeout(timeout);
-	} while (timeout);
+	if (wait_event_interruptible_timeout(tty->write_wait,
+			!tty->driver->chars_in_buffer(tty), timeout))
+		return;
 	if (tty->driver->wait_until_sent)
 		tty->driver->wait_until_sent(tty, timeout);
-stop_waiting:
-	set_current_state(TASK_RUNNING);
-	remove_wait_queue(&tty->write_wait, &wait);
 }
 
 EXPORT_SYMBOL(tty_wait_until_sent);

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/8] Char: tty_ioctl, little whitespace cleanup
  2007-05-28 13:26 [PATCH 1/8] Char: mxser_new, fix sparse warning Jiri Slaby
  2007-05-28 13:27 ` [PATCH 2/8] Char: tty_ioctl, use wait_event_interruptible_timeout Jiri Slaby
@ 2007-05-28 13:27 ` Jiri Slaby
  2007-05-28 13:28 ` [PATCH 4/8] Char: genrtc, use wait_event_interruptible Jiri Slaby
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Jiri Slaby @ 2007-05-28 13:27 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Alan Cox

tty_ioctl, little whitespace cleanup

the point is to make
while (++i < n_baud_table);
clear and assign it to the do { } loop

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>

---
commit 68362b19a0b8b05ce81b8d17743f2d0fceedb81b
tree 7472987557d2eb33ee196a16c4de26f497193e75
parent f030662cbc20e758047c5ec07396862761ea8643
author Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 21:10:32 +0200
committer Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 21:10:32 +0200

 drivers/char/tty_ioctl.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 2b6a384..3423e9e 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -261,13 +261,12 @@ void tty_termios_encode_baud_rate(struct ktermios *termios, speed_t ibaud, speed
 				termios->c_cflag |= (baud_bits[i] << IBSHIFT);
 			ifound = i;
 		}
-	}
-	while(++i < n_baud_table);
+	} while (++i < n_baud_table);
 	if (ofound == -1)
 		termios->c_cflag |= BOTHER;
 	/* Set exact input bits only if the input and output differ or the
 	   user already did */
-	if (ifound == -1 && (ibaud != obaud  || ibinput))
+	if (ifound == -1 && (ibaud != obaud || ibinput))
 		termios->c_cflag |= (BOTHER << IBSHIFT);
 }
 
@@ -560,7 +559,7 @@ static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
 		return -EFAULT;
 
 	mutex_lock(&tty->termios_mutex);
-	termios =  *tty->termios;
+	termios = *tty->termios;
 	termios.c_cc[VERASE] = tmp.sg_erase;
 	termios.c_cc[VKILL] = tmp.sg_kill;
 	set_sgflags(&termios, tmp.sg_flags);

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/8] Char: genrtc, use wait_event_interruptible
  2007-05-28 13:26 [PATCH 1/8] Char: mxser_new, fix sparse warning Jiri Slaby
  2007-05-28 13:27 ` [PATCH 2/8] Char: tty_ioctl, use wait_event_interruptible_timeout Jiri Slaby
  2007-05-28 13:27 ` [PATCH 3/8] Char: tty_ioctl, little whitespace cleanup Jiri Slaby
@ 2007-05-28 13:28 ` Jiri Slaby
  2007-05-28 13:29 ` [PATCH 5/8] Char: n_r3964, " Jiri Slaby
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Jiri Slaby @ 2007-05-28 13:28 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, rz

genrtc, use wait_event_interruptible

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit d45ae897fff813cf27d5d6ddfd92d19806831965
tree 8c985cb371c7d22c4ae939b27fe56705274452dc
parent 68362b19a0b8b05ce81b8d17743f2d0fceedb81b
author Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 21:26:32 +0200
committer Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 21:26:32 +0200

 drivers/char/genrtc.c |   22 +++++-----------------
 1 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
index 9e1fc02..69f0a29 100644
--- a/drivers/char/genrtc.c
+++ b/drivers/char/genrtc.c
@@ -173,7 +173,6 @@ static void gen_rtc_interrupt(unsigned long arg)
 static ssize_t gen_rtc_read(struct file *file, char __user *buf,
 			size_t count, loff_t *ppos)
 {
-	DECLARE_WAITQUEUE(wait, current);
 	unsigned long data;
 	ssize_t retval;
 
@@ -183,18 +182,10 @@ static ssize_t gen_rtc_read(struct file *file, char __user *buf,
 	if (file->f_flags & O_NONBLOCK && !gen_rtc_irq_data)
 		return -EAGAIN;
 
-	add_wait_queue(&gen_rtc_wait, &wait);
-	retval = -ERESTARTSYS;
-
-	while (1) {
-		set_current_state(TASK_INTERRUPTIBLE);
-		data = xchg(&gen_rtc_irq_data, 0);
-		if (data)
-			break;
-		if (signal_pending(current))
-			goto out;
-		schedule();
-	}
+	retval = wait_event_interruptible(gen_rtc_wait,
+			(data = xchg(&gen_rtc_irq_data, 0)));
+	if (retval)
+		goto out;
 
 	/* first test allows optimizer to nuke this case for 32-bit machines */
 	if (sizeof (int) != sizeof (long) && count == sizeof (unsigned int)) {
@@ -206,10 +197,7 @@ static ssize_t gen_rtc_read(struct file *file, char __user *buf,
 		retval = put_user(data, (unsigned long __user *)buf) ?:
 			sizeof(unsigned long);
 	}
- out:
-	__set_current_state(TASK_RUNNING);
-	remove_wait_queue(&gen_rtc_wait, &wait);
-
+out:
 	return retval;
 }
 

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/8] Char: n_r3964, use wait_event_interruptible
  2007-05-28 13:26 [PATCH 1/8] Char: mxser_new, fix sparse warning Jiri Slaby
                   ` (2 preceding siblings ...)
  2007-05-28 13:28 ` [PATCH 4/8] Char: genrtc, use wait_event_interruptible Jiri Slaby
@ 2007-05-28 13:29 ` Jiri Slaby
  2007-05-28 13:29 ` [PATCH 6/8] Char: rtc, " Jiri Slaby
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Jiri Slaby @ 2007-05-28 13:29 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

n_r3964, use wait_event_interruptible

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit 2b7813d0f34703e0a4b18593a3186bdc7e719c06
tree 657e6eef237faac65c0c90920e3bb1ae5a8027d9
parent d45ae897fff813cf27d5d6ddfd92d19806831965
author Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 21:45:39 +0200
committer Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 21:45:39 +0200

 drivers/char/n_r3964.c |   14 ++------------
 1 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index 14557a4..6b918b8 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -1071,8 +1071,6 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
 	struct r3964_client_info *pClient;
 	struct r3964_message *pMsg;
 	struct r3964_client_message theMsg;
-	DECLARE_WAITQUEUE(wait, current);
-
 	int count;
 
 	TRACE_L("read()");
@@ -1086,16 +1084,8 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
 				return -EAGAIN;
 			}
 			/* block until there is a message: */
-			add_wait_queue(&pInfo->read_wait, &wait);
-repeat:
-			__set_current_state(TASK_INTERRUPTIBLE);
-			pMsg = remove_msg(pInfo, pClient);
-			if (!pMsg && !signal_pending(current)) {
-				schedule();
-				goto repeat;
-			}
-			__set_current_state(TASK_RUNNING);
-			remove_wait_queue(&pInfo->read_wait, &wait);
+			wait_event_interruptible(pInfo->read_wait,
+					(pMsg = remove_msg(pInfo, pClient)));
 		}
 
 		/* If we still haven't got a message, we must have been signalled */

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/8] Char: rtc, use wait_event_interruptible
  2007-05-28 13:26 [PATCH 1/8] Char: mxser_new, fix sparse warning Jiri Slaby
                   ` (3 preceding siblings ...)
  2007-05-28 13:29 ` [PATCH 5/8] Char: n_r3964, " Jiri Slaby
@ 2007-05-28 13:29 ` Jiri Slaby
  2007-05-30  0:02   ` Andrew Morton
  2007-05-28 13:30 ` [PATCH 7/8] Char: ip2, use msleep for sleeping Jiri Slaby
  2007-05-28 13:31 ` [PATCH 8/8] Char: vt_ioctl, use wait_event_interruptible Jiri Slaby
  6 siblings, 1 reply; 10+ messages in thread
From: Jiri Slaby @ 2007-05-28 13:29 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, a.zummo

rtc, use wait_event_interruptible

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit 62bd843054a7b2b2a3e3003a6b57b6359f199837
tree 7c6912d4ed42581ca46d384ab2467bfb9d9d9dbe
parent 2b7813d0f34703e0a4b18593a3186bdc7e719c06
author Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 21:58:54 +0200
committer Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 21:58:54 +0200

 drivers/char/rtc.c |   40 +++++++++++++++-------------------------
 1 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index 20380a2..787b520 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -353,33 +353,26 @@ static ssize_t rtc_read(struct file *file, char __user *buf,
 	if (count != sizeof(unsigned int) && count !=  sizeof(unsigned long))
 		return -EINVAL;
 
-	add_wait_queue(&rtc_wait, &wait);
-
-	do {
-		/* First make it right. Then make it fast. Putting this whole
-		 * block within the parentheses of a while would be too
-		 * confusing. And no, xchg() is not the answer. */
-
-		__set_current_state(TASK_INTERRUPTIBLE);
-		
-		spin_lock_irq (&rtc_lock);
-		data = rtc_irq_data;
-		rtc_irq_data = 0;
-		spin_unlock_irq (&rtc_lock);
-
-		if (data != 0)
-			break;
+	spin_lock_irq (&rtc_lock);
+	data = rtc_irq_data;
+	rtc_irq_data = 0;
+	spin_unlock_irq (&rtc_lock);
 
+	if (data == 0) {
 		if (file->f_flags & O_NONBLOCK) {
 			retval = -EAGAIN;
 			goto out;
 		}
-		if (signal_pending(current)) {
-			retval = -ERESTARTSYS;
+		retval = wait_event_interruptible(rtc_wait, ({
+			spin_lock_irq (&rtc_lock);
+			data = rtc_irq_data;
+			rtc_irq_data = 0;
+			spin_unlock_irq (&rtc_lock);
+			data;
+		}));
+		if (retval)
 			goto out;
-		}
-		schedule();
-	} while (1);
+	}
 
 	if (count == sizeof(unsigned int))
 		retval = put_user(data, (unsigned int __user *)buf) ?: sizeof(int);
@@ -387,10 +380,7 @@ static ssize_t rtc_read(struct file *file, char __user *buf,
 		retval = put_user(data, (unsigned long __user *)buf) ?: sizeof(long);
 	if (!retval)
 		retval = count;
- out:
-	__set_current_state(TASK_RUNNING);
-	remove_wait_queue(&rtc_wait, &wait);
-
+out:
 	return retval;
 #endif
 }

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/8] Char: ip2, use msleep for sleeping
  2007-05-28 13:26 [PATCH 1/8] Char: mxser_new, fix sparse warning Jiri Slaby
                   ` (4 preceding siblings ...)
  2007-05-28 13:29 ` [PATCH 6/8] Char: rtc, " Jiri Slaby
@ 2007-05-28 13:30 ` Jiri Slaby
  2007-05-28 13:31 ` [PATCH 8/8] Char: vt_ioctl, use wait_event_interruptible Jiri Slaby
  6 siblings, 0 replies; 10+ messages in thread
From: Jiri Slaby @ 2007-05-28 13:30 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

ip2, use msleep for sleeping

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit c025c4b3eca99f50b05bc24c445b861e91226539
tree 92557f319d16e0ecd7cf5a9b1387e0805fdcdf92
parent 62bd843054a7b2b2a3e3003a6b57b6359f199837
author Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 22:21:42 +0200
committer Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 22:21:42 +0200

 drivers/char/ip2/i2ellis.c |   44 +-------------------------------------------
 1 files changed, 1 insertions(+), 43 deletions(-)

diff --git a/drivers/char/ip2/i2ellis.c b/drivers/char/ip2/i2ellis.c
index dd761a1..61ef013 100644
--- a/drivers/char/ip2/i2ellis.c
+++ b/drivers/char/ip2/i2ellis.c
@@ -43,8 +43,6 @@ static void iiEnableMailIrqIIEX(i2eBordStrPtr);
 static void iiWriteMaskII(i2eBordStrPtr, unsigned char);
 static void iiWriteMaskIIEX(i2eBordStrPtr, unsigned char);
 
-static void ii2DelayTimer(unsigned int);
-static void ii2DelayWakeup(unsigned long id);
 static void ii2Nop(void);
 
 //***************
@@ -55,8 +53,6 @@ static int ii2Safe;         // Safe I/O address for delay routine
 
 static int iiDelayed;	// Set when the iiResetDelay function is
 							// called. Cleared when ANY board is reset.
-static struct timer_list * pDelayTimer;   // Used by iiDelayTimer
-static wait_queue_head_t pDelayWait;    // Used by iiDelayTimer
 static rwlock_t Dl_spinlock;
 
 //********
@@ -86,9 +82,6 @@ static rwlock_t Dl_spinlock;
 static void
 iiEllisInit(void)
 {
-	pDelayTimer = kmalloc ( sizeof (struct timer_list), GFP_KERNEL );
-	init_timer(pDelayTimer);
-	init_waitqueue_head(&pDelayWait);
 	LOCK_INIT(&Dl_spinlock);
 }
 
@@ -106,7 +99,6 @@ iiEllisInit(void)
 static void
 iiEllisCleanup(void)
 {
-	kfree(pDelayTimer);
 }
 
 //******************************************************************************
@@ -560,19 +552,6 @@ iiInitialize(i2eBordStrPtr pB)
 	COMPLETE(pB, I2EE_GOOD);
 }
 
-//=======================================================
-// Delay Routines
-//
-// iiDelayIO
-// iiNop
-//=======================================================
-
-static void
-ii2DelayWakeup(unsigned long id)
-{
-	wake_up_interruptible ( &pDelayWait );
-}
-
 //******************************************************************************
 // Function:   ii2DelayTimer(mseconds)
 // Parameters: mseconds - number of milliseconds to delay
@@ -594,28 +573,7 @@ ii2DelayWakeup(unsigned long id)
 static void
 ii2DelayTimer(unsigned int mseconds)
 {
-	wait_queue_t wait;
-
-	init_waitqueue_entry(&wait, current);
-
-	init_timer ( pDelayTimer );
-
-	add_wait_queue(&pDelayWait, &wait);
-
-	set_current_state( TASK_INTERRUPTIBLE );
-
-	pDelayTimer->expires  = jiffies + ( mseconds + 9 ) / 10;
-	pDelayTimer->function = ii2DelayWakeup;
-	pDelayTimer->data     = 0;
-
-	add_timer ( pDelayTimer );
-
-	schedule();
-
-	set_current_state( TASK_RUNNING );
-	remove_wait_queue(&pDelayWait, &wait);
-
-	del_timer ( pDelayTimer );
+	msleep_interruptible(mseconds);
 }
 
 #if 0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 8/8] Char: vt_ioctl, use wait_event_interruptible
  2007-05-28 13:26 [PATCH 1/8] Char: mxser_new, fix sparse warning Jiri Slaby
                   ` (5 preceding siblings ...)
  2007-05-28 13:30 ` [PATCH 7/8] Char: ip2, use msleep for sleeping Jiri Slaby
@ 2007-05-28 13:31 ` Jiri Slaby
  2007-05-30  0:08   ` Andrew Morton
  6 siblings, 1 reply; 10+ messages in thread
From: Jiri Slaby @ 2007-05-28 13:31 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

vt_ioctl, use wait_event_interruptible

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

---
commit fbe1931e02f11b2fef771ff1698f1598b3567520
tree fcfcd72a5619f6e26598ac2ee3132aed4b070987
parent c025c4b3eca99f50b05bc24c445b861e91226539
author Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 22:58:17 +0200
committer Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 22:58:17 +0200

 drivers/char/vt_ioctl.c |   22 ++++------------------
 1 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index c6f6f42..2056367 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -1035,12 +1035,8 @@ static DECLARE_WAIT_QUEUE_HEAD(vt_activate_queue);
 int vt_waitactive(int vt)
 {
 	int retval;
-	DECLARE_WAITQUEUE(wait, current);
-
-	add_wait_queue(&vt_activate_queue, &wait);
-	for (;;) {
-		retval = 0;
 
+	return wait_event_interruptible(vt_activate_queue, ({
 		/*
 		 * Synchronize with redraw_screen(). By acquiring the console
 		 * semaphore we make sure that the console switch is completed
@@ -1049,20 +1045,10 @@ int vt_waitactive(int vt)
 		 * updated, but the console switch hasn't been completed.
 		 */
 		acquire_console_sem();
-		set_current_state(TASK_INTERRUPTIBLE);
-		if (vt == fg_console) {
-			release_console_sem();
-			break;
-		}
+		retval = vt == fg_console;
 		release_console_sem();
-		retval = -EINTR;
-		if (signal_pending(current))
-			break;
-		schedule();
-	}
-	remove_wait_queue(&vt_activate_queue, &wait);
-	__set_current_state(TASK_RUNNING);
-	return retval;
+		retval;
+	}));
 }
 
 #define vt_wake_waitactive() wake_up(&vt_activate_queue)

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/8] Char: rtc, use wait_event_interruptible
  2007-05-28 13:29 ` [PATCH 6/8] Char: rtc, " Jiri Slaby
@ 2007-05-30  0:02   ` Andrew Morton
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2007-05-30  0:02 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: linux-kernel, a.zummo

On Mon, 28 May 2007 15:29:50 +0200 (CEST)
Jiri Slaby <jirislaby@gmail.com> wrote:

> rtc, use wait_event_interruptible
> 
> Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
> 
> ---
> commit 62bd843054a7b2b2a3e3003a6b57b6359f199837
> tree 7c6912d4ed42581ca46d384ab2467bfb9d9d9dbe
> parent 2b7813d0f34703e0a4b18593a3186bdc7e719c06
> author Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 21:58:54 +0200
> committer Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 21:58:54 +0200
> 
>  drivers/char/rtc.c |   40 +++++++++++++++-------------------------
>  1 files changed, 15 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
> index 20380a2..787b520 100644
> --- a/drivers/char/rtc.c
> +++ b/drivers/char/rtc.c
> @@ -353,33 +353,26 @@ static ssize_t rtc_read(struct file *file, char __user *buf,
>  	if (count != sizeof(unsigned int) && count !=  sizeof(unsigned long))
>  		return -EINVAL;
>  
> -	add_wait_queue(&rtc_wait, &wait);
> -
> -	do {
> -		/* First make it right. Then make it fast. Putting this whole
> -		 * block within the parentheses of a while would be too
> -		 * confusing. And no, xchg() is not the answer. */
> -
> -		__set_current_state(TASK_INTERRUPTIBLE);
> -		
> -		spin_lock_irq (&rtc_lock);
> -		data = rtc_irq_data;
> -		rtc_irq_data = 0;
> -		spin_unlock_irq (&rtc_lock);
> -
> -		if (data != 0)
> -			break;
> +	spin_lock_irq (&rtc_lock);
> +	data = rtc_irq_data;
> +	rtc_irq_data = 0;
> +	spin_unlock_irq (&rtc_lock);
>  
> +	if (data == 0) {
>  		if (file->f_flags & O_NONBLOCK) {
>  			retval = -EAGAIN;
>  			goto out;
>  		}
> -		if (signal_pending(current)) {
> -			retval = -ERESTARTSYS;
> +		retval = wait_event_interruptible(rtc_wait, ({
> +			spin_lock_irq (&rtc_lock);
> +			data = rtc_irq_data;
> +			rtc_irq_data = 0;
> +			spin_unlock_irq (&rtc_lock);
> +			data;
> +		}));
> +		if (retval)
>  			goto out;
> -		}
> -		schedule();
> -	} while (1);
> +	}
>  
>  	if (count == sizeof(unsigned int))
>  		retval = put_user(data, (unsigned int __user *)buf) ?: sizeof(int);
> @@ -387,10 +380,7 @@ static ssize_t rtc_read(struct file *file, char __user *buf,
>  		retval = put_user(data, (unsigned long __user *)buf) ?: sizeof(long);
>  	if (!retval)
>  		retval = count;
> - out:
> -	__set_current_state(TASK_RUNNING);
> -	remove_wait_queue(&rtc_wait, &wait);
> -
> +out:
>  	return retval;
>  #endif

erm, I'm not sure that really improved the code.

Note that wait_event_interruptible() evaluates the condition twice, so
that's now three copies we have in there.  A little helper function would
make this all much better.

Also, feel free to sneak in a s/spin_lock_irq (/spin_lock_irq(/ cleanup
when making changes like this.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 8/8] Char: vt_ioctl, use wait_event_interruptible
  2007-05-28 13:31 ` [PATCH 8/8] Char: vt_ioctl, use wait_event_interruptible Jiri Slaby
@ 2007-05-30  0:08   ` Andrew Morton
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2007-05-30  0:08 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: linux-kernel

On Mon, 28 May 2007 15:31:12 +0200 (CEST)
Jiri Slaby <jirislaby@gmail.com> wrote:

> vt_ioctl, use wait_event_interruptible
> 
> Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
> 
> ---
> commit fbe1931e02f11b2fef771ff1698f1598b3567520
> tree fcfcd72a5619f6e26598ac2ee3132aed4b070987
> parent c025c4b3eca99f50b05bc24c445b861e91226539
> author Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 22:58:17 +0200
> committer Jiri Slaby <jirislaby@gmail.com> Sat, 26 May 2007 22:58:17 +0200
> 
>  drivers/char/vt_ioctl.c |   22 ++++------------------
>  1 files changed, 4 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
> index c6f6f42..2056367 100644
> --- a/drivers/char/vt_ioctl.c
> +++ b/drivers/char/vt_ioctl.c
> @@ -1035,12 +1035,8 @@ static DECLARE_WAIT_QUEUE_HEAD(vt_activate_queue);
>  int vt_waitactive(int vt)
>  {
>  	int retval;
> -	DECLARE_WAITQUEUE(wait, current);
> -
> -	add_wait_queue(&vt_activate_queue, &wait);
> -	for (;;) {
> -		retval = 0;
>  
> +	return wait_event_interruptible(vt_activate_queue, ({
>  		/*
>  		 * Synchronize with redraw_screen(). By acquiring the console
>  		 * semaphore we make sure that the console switch is completed
> @@ -1049,20 +1045,10 @@ int vt_waitactive(int vt)
>  		 * updated, but the console switch hasn't been completed.
>  		 */
>  		acquire_console_sem();
> -		set_current_state(TASK_INTERRUPTIBLE);
> -		if (vt == fg_console) {
> -			release_console_sem();
> -			break;
> -		}
> +		retval = vt == fg_console;
>  		release_console_sem();
> -		retval = -EINTR;
> -		if (signal_pending(current))
> -			break;
> -		schedule();
> -	}
> -	remove_wait_queue(&vt_activate_queue, &wait);
> -	__set_current_state(TASK_RUNNING);
> -	return retval;
> +		retval;
> +	}));
>  }
>  

So we end up with

int vt_waitactive(int vt)
{
	int retval;

	return wait_event_interruptible(vt_activate_queue, ({
		/*
		 * Synchronize with redraw_screen(). By acquiring the console
		 * semaphore we make sure that the console switch is completed
		 * before we return. If we didn't wait for the semaphore, we
		 * could return at a point where fg_console has already been
		 * updated, but the console switch hasn't been completed.
		 */
		acquire_console_sem();
		retval = vt == fg_console;
		release_console_sem();
		retval;
	}));
}

Again, I do think this needs a helper function.  Or something.  The handling
of `retval' in there is pretty perverse.  We're modifying a local variable
within the macro and then returning it by value?  Perhaps a bit cleaner
would be to move `retval' inside the macro body.

But a helper function would be better.  Again, remember that the macro
evaluates that expression twice - you may find that the helper function
even generates less code.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-05-30  0:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-28 13:26 [PATCH 1/8] Char: mxser_new, fix sparse warning Jiri Slaby
2007-05-28 13:27 ` [PATCH 2/8] Char: tty_ioctl, use wait_event_interruptible_timeout Jiri Slaby
2007-05-28 13:27 ` [PATCH 3/8] Char: tty_ioctl, little whitespace cleanup Jiri Slaby
2007-05-28 13:28 ` [PATCH 4/8] Char: genrtc, use wait_event_interruptible Jiri Slaby
2007-05-28 13:29 ` [PATCH 5/8] Char: n_r3964, " Jiri Slaby
2007-05-28 13:29 ` [PATCH 6/8] Char: rtc, " Jiri Slaby
2007-05-30  0:02   ` Andrew Morton
2007-05-28 13:30 ` [PATCH 7/8] Char: ip2, use msleep for sleeping Jiri Slaby
2007-05-28 13:31 ` [PATCH 8/8] Char: vt_ioctl, use wait_event_interruptible Jiri Slaby
2007-05-30  0:08   ` Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.