Char: mxser_new, fix sparse warning
Subsystems (2)
PATCH 1/8 Char: mxser_new, fix sparse warning
mxser_new, fix sparse warning
---
commit 29f15033f00e36f622d0bcd5a2dd0f9a49981481
tree 2a332865460a2775256b5087f8da6ff8f1befdf0
parent 1f023432798b6e6fd52ad81af0eab250e1a71449
author Jiri Slaby <[email protected]> Sat, 26 May 2007 18:14:21 +0200 committer Jiri Slaby <[email protected]> Sat, 26 May 2007 18:14:21 +0200
drivers/char/mxser_new.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/char/mxser_new.c +1 -1
@@ -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;
PATCH 2/8 Char: tty_ioctl, use wait_event_interruptible_timeout
tty_ioctl, use wait_event_interruptible_timeout
---
commit f030662cbc20e758047c5ec07396862761ea8643
tree 113645cd1e51b8469b77022f2c68fdb94ab54449
parent 29f15033f00e36f622d0bcd5a2dd0f9a49981481
author Jiri Slaby <[email protected]> Sat, 26 May 2007 20:56:41 +0200 committer Jiri Slaby <[email protected]> Sat, 26 May 2007 20:56:41 +0200
drivers/char/tty_ioctl.c | 21 +++------------------ 1 files changed, 3 insertions(+), 18 deletions(-)
drivers/char/tty_ioctl.c +3 -18
@@ -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);
PATCH 3/8 Char: tty_ioctl, little whitespace cleanup
In reply to Jiri Slabytty_ioctl, little whitespace cleanup
the point is to make
while (++i < n_baud_table);
clear and assign it to the do { } loop
---
commit 68362b19a0b8b05ce81b8d17743f2d0fceedb81b
tree 7472987557d2eb33ee196a16c4de26f497193e75
parent f030662cbc20e758047c5ec07396862761ea8643
author Jiri Slaby <[email protected]> Sat, 26 May 2007 21:10:32 +0200 committer Jiri Slaby <[email protected]> Sat, 26 May 2007 21:10:32 +0200
drivers/char/tty_ioctl.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/char/tty_ioctl.c +3 -4
@@ -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);
PATCH 4/8 Char: genrtc, use wait_event_interruptible
In reply to Jiri Slabygenrtc, use wait_event_interruptible
---
commit d45ae897fff813cf27d5d6ddfd92d19806831965
tree 8c985cb371c7d22c4ae939b27fe56705274452dc
parent 68362b19a0b8b05ce81b8d17743f2d0fceedb81b
author Jiri Slaby <[email protected]> Sat, 26 May 2007 21:26:32 +0200 committer Jiri Slaby <[email protected]> Sat, 26 May 2007 21:26:32 +0200
drivers/char/genrtc.c | 22 +++++----------------- 1 files changed, 5 insertions(+), 17 deletions(-)
drivers/char/genrtc.c +5 -17
@@ -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; }
PATCH 5/8 Char: n_r3964, use wait_event_interruptible
In reply to Jiri Slabyn_r3964, use wait_event_interruptible
---
commit 2b7813d0f34703e0a4b18593a3186bdc7e719c06
tree 657e6eef237faac65c0c90920e3bb1ae5a8027d9
parent d45ae897fff813cf27d5d6ddfd92d19806831965
author Jiri Slaby <[email protected]> Sat, 26 May 2007 21:45:39 +0200 committer Jiri Slaby <[email protected]> Sat, 26 May 2007 21:45:39 +0200
drivers/char/n_r3964.c | 14 ++------------ 1 files changed, 2 insertions(+), 12 deletions(-)
drivers/char/n_r3964.c +2 -12
@@ -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 */
PATCH 6/8 Char: rtc, use wait_event_interruptible
In reply to Jiri Slabyrtc, use wait_event_interruptible
---
commit 62bd843054a7b2b2a3e3003a6b57b6359f199837
tree 7c6912d4ed42581ca46d384ab2467bfb9d9d9dbe
parent 2b7813d0f34703e0a4b18593a3186bdc7e719c06
author Jiri Slaby <[email protected]> Sat, 26 May 2007 21:58:54 +0200 committer Jiri Slaby <[email protected]> Sat, 26 May 2007 21:58:54 +0200
drivers/char/rtc.c | 40 +++++++++++++++------------------------- 1 files changed, 15 insertions(+), 25 deletions(-)
drivers/char/rtc.c +15 -25
@@ -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 }
Re: [PATCH 6/8] Char: rtc, use wait_event_interruptible
Quoted 67 lines · On Mon, 28 May 2007 15:29:50 +0200 (CEST) Jiri Slaby <[email protected]>…
rtc, use
wait_event_interruptibleSigned-off-by Jiri Slaby <[email protected]>---
commit62bd843054a7b2b2a3e3003a6b57b6359f199837
tree7c6912d4ed42581ca46d384ab2467bfb9d9d9dbe
parent2b7813d0f34703e0a4b18593a3186bdc7e719c06
author Jiri Slaby <[email protected]> Sat, 26 May 2007 21:58:54 +0200 committer Jiri Slaby <[email protected]> Sat, 26 May 2007 21:58:54 +0200drivers/char/rtc.c | 40 +++++++++++++++------------------------- 1 files changed, 15 insertions(+), 25 deletions(-)drivers/char/rtc.c +14
-21@@ -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 );
drivers/char/rtc.c static ssize_t rtc_read(struct file *file, char __user *buf, · line 385
Quoted 10 lines
drivers/char/rtc.c +1
-4@@ -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.
PATCH 7/8 Char: ip2, use msleep for sleeping
In reply to Jiri Slabyip2, use msleep for sleeping
---
commit c025c4b3eca99f50b05bc24c445b861e91226539
tree 92557f319d16e0ecd7cf5a9b1387e0805fdcdf92
parent 62bd843054a7b2b2a3e3003a6b57b6359f199837
author Jiri Slaby <[email protected]> Sat, 26 May 2007 22:21:42 +0200 committer Jiri Slaby <[email protected]> Sat, 26 May 2007 22:21:42 +0200
drivers/char/ip2/i2ellis.c | 44 +------------------------------------------- 1 files changed, 1 insertions(+), 43 deletions(-)
drivers/char/ip2/i2ellis.c +1 -43
@@ -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 routinestatic 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
PATCH 8/8 Char: vt_ioctl, use wait_event_interruptible
In reply to Jiri Slabyvt_ioctl, use wait_event_interruptible
---
commit fbe1931e02f11b2fef771ff1698f1598b3567520
tree fcfcd72a5619f6e26598ac2ee3132aed4b070987
parent c025c4b3eca99f50b05bc24c445b861e91226539
author Jiri Slaby <[email protected]> Sat, 26 May 2007 22:58:17 +0200 committer Jiri Slaby <[email protected]> Sat, 26 May 2007 22:58:17 +0200
drivers/char/vt_ioctl.c | 22 ++++------------------ 1 files changed, 4 insertions(+), 18 deletions(-)
drivers/char/vt_ioctl.c +4 -18
@@ -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)
Re: [PATCH 8/8] Char: vt_ioctl, use wait_event_interruptible
Quoted 45 lines · On Mon, 28 May 2007 15:31:12 +0200 (CEST) Jiri Slaby <[email protected]>…
vt_ioctl, usewait_event_interruptibleSigned-off-by Jiri Slaby <[email protected]>---
commitfbe1931e02f11b2fef771ff1698f1598b3567520
treefcfcd72a5619f6e26598ac2ee3132aed4b070987
parentc025c4b3eca99f50b05bc24c445b861e91226539
author Jiri Slaby <[email protected]> Sat, 26 May 2007 22:58:17 +0200 committer Jiri Slaby <[email protected]> Sat, 26 May 2007 22:58:17 +0200drivers/char/vt_ioctl.c | 22 ++++------------------ 1 files changed, 4 insertions(+), 18 deletions(-)drivers/char/vt_ioctl.c +2
-12@@ -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))
drivers/char/vt_ioctl.c int vt_waitactive(int vt) · line 1053
Quoted 10 lines
drivers/char/vt_ioctl.c +2
-6-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.