]> git.karo-electronics.de Git - linux-beck.git/blobdiff - drivers/char/tty_port.c
tty_port: coding style cleaning pass
[linux-beck.git] / drivers / char / tty_port.c
index 2e8552dc5edaef207604f2b3b51a26eff898e3ca..41b314cfda47c7820790680df524753f2698b506 100644 (file)
@@ -99,10 +99,11 @@ EXPORT_SYMBOL(tty_port_tty_set);
 
 static void tty_port_shutdown(struct tty_port *port)
 {
+       mutex_lock(&port->mutex);
        if (port->ops->shutdown &&
                test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags))
                        port->ops->shutdown(port);
-
+       mutex_unlock(&port->mutex);
 }
 
 /**
@@ -198,7 +199,7 @@ EXPORT_SYMBOL(tty_port_lower_dtr_rts);
  *     management of these lines. Note that the dtr/rts raise is done each
  *     iteration as a hangup may have previously dropped them while we wait.
  */
+
 int tty_port_block_til_ready(struct tty_port *port,
                                struct tty_struct *tty, struct file *filp)
 {
@@ -219,8 +220,11 @@ int tty_port_block_til_ready(struct tty_port *port,
 
        /* if non-blocking mode is set we can pass directly to open unless
           the port has just hung up or is in another error state */
-       if ((filp->f_flags & O_NONBLOCK) ||
-                       (tty->flags & (1 << TTY_IO_ERROR))) {
+       if (tty->flags & (1 << TTY_IO_ERROR)) {
+               port->flags |= ASYNC_NORMAL_ACTIVE;
+               return 0;
+       }
+       if (filp->f_flags & O_NONBLOCK) {
                /* Indicate we are open */
                if (tty->termios->c_cflag & CBAUD)
                        tty_port_raise_dtr_rts(port);
@@ -250,7 +254,8 @@ int tty_port_block_til_ready(struct tty_port *port,
                        tty_port_raise_dtr_rts(port);
 
                prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
-               /* Check for a hangup or uninitialised port. Return accordingly */
+               /* Check for a hangup or uninitialised port.
+                                                       Return accordingly */
                if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
                        if (port->flags & ASYNC_HUP_NOTIFY)
                                retval = -EAGAIN;
@@ -282,11 +287,11 @@ int tty_port_block_til_ready(struct tty_port *port,
                port->flags |= ASYNC_NORMAL_ACTIVE;
        spin_unlock_irqrestore(&port->lock, flags);
        return retval;
-       
 }
 EXPORT_SYMBOL(tty_port_block_til_ready);
 
-int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct file *filp)
+int tty_port_close_start(struct tty_port *port,
+                               struct tty_struct *tty, struct file *filp)
 {
        unsigned long flags;
 
@@ -296,7 +301,7 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f
                return 0;
        }
 
-       iftty->count == 1 && port->count != 1) {
+       if (tty->count == 1 && port->count != 1) {
                printk(KERN_WARNING
                    "tty_port_close_start: tty->count = 1 port count = %d.\n",
                                                                port->count);
@@ -328,8 +333,8 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f
                long timeout;
 
                if (bps > 1200)
-                       timeout = max_t(long, (HZ * 10 * port->drain_delay) / bps,
-                                                               HZ / 10);
+                       timeout = max_t(long,
+                               (HZ * 10 * port->drain_delay) / bps, HZ / 10);
                else
                        timeout = 2 * HZ;
                schedule_timeout_interruptible(timeout);
@@ -378,3 +383,36 @@ void tty_port_close(struct tty_port *port, struct tty_struct *tty,
        tty_port_tty_set(port, NULL);
 }
 EXPORT_SYMBOL(tty_port_close);
+
+int tty_port_open(struct tty_port *port, struct tty_struct *tty,
+                                                       struct file *filp)
+{
+       spin_lock_irq(&port->lock);
+       if (!tty_hung_up_p(filp))
+               ++port->count;
+       spin_unlock_irq(&port->lock);
+       tty_port_tty_set(port, tty);
+
+       /*
+        * Do the device-specific open only if the hardware isn't
+        * already initialized. Serialize open and shutdown using the
+        * port mutex.
+        */
+
+       mutex_lock(&port->mutex);
+
+       if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) {
+               if (port->ops->activate) {
+                       int retval = port->ops->activate(port, tty);
+                       if (retval) {
+                               mutex_unlock(&port->mutex);
+                               return retval;
+                       }
+               }
+               set_bit(ASYNCB_INITIALIZED, &port->flags);
+       }
+       mutex_unlock(&port->mutex);
+       return tty_port_block_til_ready(port, tty, filp);
+}
+
+EXPORT_SYMBOL(tty_port_open);