[PATCH 33/67] serial: Use block_til_ready helper

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Greg Kroah-Hartman
Date: Thursday, August 5, 2010 - 3:23 pm

From: Alan Cox <alan@linux.intel.com>

Our code now rather closely resembles the helper, so switch to it.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/serial/serial_core.c |   87 +-----------------------------------------
 1 files changed, 1 insertions(+), 86 deletions(-)

diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 0603e0d..a55751a 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -1526,91 +1526,6 @@ static void uart_dtr_rts(struct tty_port *port, int onoff)
 		uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
 }
 
-/*
- * Block the open until the port is ready.  We must be called with
- * the per-port semaphore held.
- */
-static int
-uart_block_til_ready(struct file *filp, struct uart_state *state)
-{
-	DECLARE_WAITQUEUE(wait, current);
-	struct tty_port *port = &state->port;
-	unsigned long flags;
-
-	spin_lock_irqsave(&port->lock, flags);
-	if (!tty_hung_up_p(filp))
-		port->count--;
-	port->blocked_open++;
-	spin_unlock_irqrestore(&port->lock, flags);
-
-	add_wait_queue(&port->open_wait, &wait);
-	while (1) {
-		set_current_state(TASK_INTERRUPTIBLE);
-
-		/*
-		 * If we have been hung up, tell userspace/restart open.
-		 */
-		if (tty_hung_up_p(filp) || port->tty == NULL)
-			break;
-
-		/*
-		 * If the port has been closed, tell userspace/restart open.
-		 */
-		if (!(port->flags & ASYNC_INITIALIZED))
-			break;
-
-		/*
-		 * If non-blocking mode is set, or CLOCAL mode is set,
-		 * we don't want to wait for the modem status lines to
-		 * indicate that the port is ready.
-		 *
-		 * Also, if the port is not enabled/configured, we want
-		 * to allow the open to succeed here.  Note that we will
-		 * have set TTY_IO_ERROR for a non-existant port.
-		 */
-		if ((filp->f_flags & O_NONBLOCK) ||
-		    (port->tty->termios->c_cflag & CLOCAL) ||
-		    (port->tty->flags & (1 << TTY_IO_ERROR)))
-			break;
-
-		/*
-		 * Set DTR to allow modem to know we're waiting.  Do
-		 * not set RTS here - we want to make sure we catch
-		 * the data from the modem.
-		 */
-		if (port->tty->termios->c_cflag & CBAUD)
-			tty_port_raise_dtr_rts(port);
-
-		/*
-		 * and wait for the carrier to indicate that the
-		 * modem is ready for us.
-		 */
-		if (tty_port_carrier_raised(port))
-			break;
-
-		schedule();
-
-		if (signal_pending(current))
-			break;
-	}
-	set_current_state(TASK_RUNNING);
-	remove_wait_queue(&port->open_wait, &wait);
-
-	spin_lock_irqsave(&port->lock, flags);
-	if (!tty_hung_up_p(filp))
-		port->count++;
-	port->blocked_open--;
-	spin_unlock_irqrestore(&port->lock, flags);
-
-	if (signal_pending(current))
-		return -ERESTARTSYS;
-
-	if (!port->tty || tty_hung_up_p(filp))
-		return -EAGAIN;
-
-	return 0;
-}
-
 static struct uart_state *uart_get(struct uart_driver *drv, int line)
 {
 	struct uart_state *state;
@@ -1719,7 +1634,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
 	 */
 	mutex_unlock(&port->mutex);
 	if (retval == 0)
-		retval = uart_block_til_ready(filp, state);
+		retval = tty_port_block_til_ready(port, tty, filp);
 
 	/*
 	 * If this is the first open to succeed, adjust things to suit.
-- 
1.7.2

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[GIT PATCH] TTY patches for 2.6.36, Greg KH, (Thu Aug 5, 2:35 pm)
[PATCH 01/67] n_gsm.c: removed duplicated #includes, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 02/67] serial: There's no config CONSOLE, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 03/67] vt: clean up the code - use kernel library, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 04/67] serial: add UART_CAP_EFR and UART_CAP_SLEEP ..., Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 05/67] mrst_max3110: add UART driver for Max3110 on ..., Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 06/67] max3110 sanity check a register, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 07/67] serial: replace open coded mutex with a real ..., Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 08/67] serial: fix wakup races in the mrst_max3110 ..., Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 09/67] tty: Remove Hayes ESP ioctls, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 10/67] tty: remove remaining Hayes ESP ioctls, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 11/67] tty: Add EXTPROC support for LINEMODE, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 12/67] vt/console: try harder to print output when ..., Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 13/67] stallion: prune lock_kernel calls, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 14/67] istallion: use bit ops for the board flags, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 15/67] riscom8: kill use of lock_kernel, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 16/67] isicom: kill off the BKL, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 17/67] rocket: kill BKL, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 18/67] synclink: kill the big kernel lock, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 19/67] cyclades: Kill off BKL usage, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 20/67] epca: Kill the big kernel lock, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 21/67] specialix: Kill the BKL, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 22/67] tty: Fix the digi acceleport driver NULL checks, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 23/67] synclink: reworking locking a bit, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 24/67] tty: serial - fix various misuses/mishandlin ..., Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 25/67] tty: serial - fix tty back references in termios, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 26/67] tty: serial - fix tty referencing in set_ldisc, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 27/67] vc: Locking clean up, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 28/67] tty: Make vt's have a tty_port, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 29/67] tty: Move the vt_tty field from the vc_data ..., Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 30/67] serial: Change the wait for carrier locking, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 31/67] serial: add port helpers, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 32/67] serial: trim locking on the helpers, Greg Kroah-Hartman, (Thu Aug 5, 3:22 pm)
[PATCH 33/67] serial: Use block_til_ready helper, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 34/67] serial: fix termios settings in open, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 35/67] tty: replace BKL with a new tty_lock, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 36/67] tty: never hold BTM while getting tty_mutex, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 37/67] tty: fix console_sem lock order, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 38/67] cdc-acm: remove dead code, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 39/67] tty: introduce wait_event_interruptible_tty, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 40/67] tty: reorder ldisc locking, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 41/67] tty: untangle locking of wait_until_sent, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 42/67] tty: remove tty_lock_nested, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 43/67] tty: implement BTM as mutex instead of BKL, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 44/67] tty: release BTM while sleeping in block_til ..., Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 45/67] 8250: fix set_ldisc operation, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 46/67] tty: avoid recursive BTM in pty_close, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 47/67] serial: max3107: introduce a max3107 driver, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 48/67] serial: max3107: Abstract out the platform s ..., Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 49/67] tty_io: remove casts from void*, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 50/67] vt: Fix warning: statement with no effect du ..., Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 51/67] serial: crisv10: formatting of pointers in p ..., Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 53/67] serial: fix missing bit coverage of ASYNC_FLAGS, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 54/67] serial: general fixes in the serial_rs485 st ..., Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 55/67] serial: mcf: don't take spinlocks in already ..., Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 56/67] serial: MMIO32 support for 8250_early.c, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 57/67] timbuart: use __devinit and __devexit macros ..., Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 58/67] serial: 68328serial.c: remove dead (ALMA_ANS ..., Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 59/67] serial: add support for OX16PCI958 card, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 60/67] mxser: remove unnesesary NULL check, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 61/67] hsu: driver for Medfield High Speed UART device, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 62/67] hsu: add a periodic timer to check dma rx ch ..., Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 63/67] hsu: some code cleanup, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 64/67] hsu: call PCI pm hooks in suspend/resume fun ..., Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
[PATCH 65/67] serial: max3107: Fix gpiolib support, Greg Kroah-Hartman, (Thu Aug 5, 3:23 pm)
Re: [GIT PATCH] TTY patches for 2.6.36, Linus Torvalds, (Fri Aug 6, 11:40 am)
Re: [GIT PATCH] TTY patches for 2.6.36, Greg KH, (Fri Aug 6, 11:51 am)
Re: [GIT PATCH] TTY patches for 2.6.36, Greg KH, (Fri Aug 6, 12:37 pm)
Re: [GIT PATCH] TTY patches for 2.6.36, Linus Torvalds, (Fri Aug 6, 12:38 pm)
[PATCH retry] tty: implement BTM as mutex instead of BKL, Arnd Bergmann, (Fri Aug 6, 12:40 pm)
Re: [GIT PATCH] TTY patches for 2.6.36, Arnd Bergmann, (Fri Aug 6, 12:40 pm)
Re: [GIT PATCH] TTY patches for 2.6.36, Alan Cox, (Fri Aug 6, 12:45 pm)
Re: [GIT PATCH] TTY patches for 2.6.36, Arnd Bergmann, (Fri Aug 6, 12:58 pm)
Re: [GIT PATCH] TTY patches for 2.6.36, Linus Torvalds, (Fri Aug 6, 1:11 pm)
Re: [GIT PATCH] TTY patches for 2.6.36, Arnd Bergmann, (Fri Aug 6, 1:19 pm)
Re: [GIT PATCH] TTY patches for 2.6.36, Greg KH, (Fri Aug 6, 1:22 pm)
Re: [GIT PATCH] TTY patches for 2.6.36, Andy Whitcroft, (Mon Aug 9, 9:06 am)
Re: [GIT PATCH] TTY patches for 2.6.36, Arnd Bergmann, (Mon Aug 9, 11:38 am)
Re: [GIT PATCH] TTY patches for 2.6.36, Alan Cox, (Mon Aug 9, 12:24 pm)
Re: [GIT PATCH] TTY patches for 2.6.36, Andy Whitcroft, (Tue Aug 10, 12:31 am)