Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-arm
[safe/jmp/linux-2.6] / drivers / char / tty_port.c
index 43a1907..a3bd1d0 100644 (file)
@@ -29,6 +29,7 @@ void tty_port_init(struct tty_port *port)
        spin_lock_init(&port->lock);
        port->close_delay = (50 * HZ) / 100;
        port->closing_wait = (3000 * HZ) / 100;
+       kref_init(&port->kref);
 }
 EXPORT_SYMBOL(tty_port_init);
 
@@ -56,6 +57,23 @@ void tty_port_free_xmit_buf(struct tty_port *port)
 }
 EXPORT_SYMBOL(tty_port_free_xmit_buf);
 
+static void tty_port_destructor(struct kref *kref)
+{
+       struct tty_port *port = container_of(kref, struct tty_port, kref);
+       if (port->xmit_buf)
+               free_page((unsigned long)port->xmit_buf);
+       if (port->ops->destruct)
+               port->ops->destruct(port);
+       else
+               kfree(port);
+}
+
+void tty_port_put(struct tty_port *port)
+{
+       if (port)
+               kref_put(&port->kref, tty_port_destructor);
+}
+EXPORT_SYMBOL(tty_port_put);
 
 /**
  *     tty_port_tty_get        -       get a tty reference
@@ -101,7 +119,7 @@ EXPORT_SYMBOL(tty_port_tty_set);
 static void tty_port_shutdown(struct tty_port *port)
 {
        mutex_lock(&port->mutex);
-       if (port->ops->shutdown &&
+       if (port->ops->shutdown && !port->console &&
                test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags))
                        port->ops->shutdown(port);
        mutex_unlock(&port->mutex);
@@ -409,6 +427,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
        mutex_lock(&port->mutex);
 
        if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) {
+               clear_bit(TTY_IO_ERROR, &tty->flags);
                if (port->ops->activate) {
                        int retval = port->ops->activate(port, tty);
                        if (retval) {
@@ -417,7 +436,6 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
                        }
                }
                set_bit(ASYNCB_INITIALIZED, &port->flags);
-               clear_bit(TTY_IO_ERROR, &tty->flags);
        }
        mutex_unlock(&port->mutex);
        return tty_port_block_til_ready(port, tty, filp);