Commit 266e37ef authored by Jiri Slaby's avatar Jiri Slaby Committed by Greg Kroah-Hartman

TTY: usb/u_serial, add tty_port

And use count from there.
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8e328416
...@@ -94,12 +94,12 @@ struct gs_buf { ...@@ -94,12 +94,12 @@ struct gs_buf {
* (and thus for each /dev/ node). * (and thus for each /dev/ node).
*/ */
struct gs_port { struct gs_port {
struct tty_port port;
spinlock_t port_lock; /* guard port_* access */ spinlock_t port_lock; /* guard port_* access */
struct gserial *port_usb; struct gserial *port_usb;
struct tty_struct *port_tty; struct tty_struct *port_tty;
unsigned open_count;
bool openclose; /* open/close in progress */ bool openclose; /* open/close in progress */
u8 port_num; u8 port_num;
...@@ -734,9 +734,9 @@ static int gs_open(struct tty_struct *tty, struct file *file) ...@@ -734,9 +734,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
spin_lock_irq(&port->port_lock); spin_lock_irq(&port->port_lock);
/* already open? Great. */ /* already open? Great. */
if (port->open_count) { if (port->port.count) {
status = 0; status = 0;
port->open_count++; port->port.count++;
/* currently opening/closing? wait ... */ /* currently opening/closing? wait ... */
} else if (port->openclose) { } else if (port->openclose) {
...@@ -795,7 +795,7 @@ static int gs_open(struct tty_struct *tty, struct file *file) ...@@ -795,7 +795,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
tty->driver_data = port; tty->driver_data = port;
port->port_tty = tty; port->port_tty = tty;
port->open_count = 1; port->port.count = 1;
port->openclose = false; port->openclose = false;
/* if connected, start the I/O stream */ /* if connected, start the I/O stream */
...@@ -837,11 +837,11 @@ static void gs_close(struct tty_struct *tty, struct file *file) ...@@ -837,11 +837,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
spin_lock_irq(&port->port_lock); spin_lock_irq(&port->port_lock);
if (port->open_count != 1) { if (port->port.count != 1) {
if (port->open_count == 0) if (port->port.count == 0)
WARN_ON(1); WARN_ON(1);
else else
--port->open_count; --port->port.count;
goto exit; goto exit;
} }
...@@ -851,7 +851,7 @@ static void gs_close(struct tty_struct *tty, struct file *file) ...@@ -851,7 +851,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
* and sleep if necessary * and sleep if necessary
*/ */
port->openclose = true; port->openclose = true;
port->open_count = 0; port->port.count = 0;
gser = port->port_usb; gser = port->port_usb;
if (gser && gser->disconnect) if (gser && gser->disconnect)
...@@ -1034,6 +1034,7 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) ...@@ -1034,6 +1034,7 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
if (port == NULL) if (port == NULL)
return -ENOMEM; return -ENOMEM;
tty_port_init(&port->port);
spin_lock_init(&port->port_lock); spin_lock_init(&port->port_lock);
init_waitqueue_head(&port->close_wait); init_waitqueue_head(&port->close_wait);
init_waitqueue_head(&port->drain_wait); init_waitqueue_head(&port->drain_wait);
...@@ -1155,7 +1156,7 @@ static int gs_closed(struct gs_port *port) ...@@ -1155,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
int cond; int cond;
spin_lock_irq(&port->port_lock); spin_lock_irq(&port->port_lock);
cond = (port->open_count == 0) && !port->openclose; cond = (port->port.count == 0) && !port->openclose;
spin_unlock_irq(&port->port_lock); spin_unlock_irq(&port->port_lock);
return cond; return cond;
} }
...@@ -1268,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num) ...@@ -1268,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
/* if it's already open, start I/O ... and notify the serial /* if it's already open, start I/O ... and notify the serial
* protocol about open/close status (connect/disconnect). * protocol about open/close status (connect/disconnect).
*/ */
if (port->open_count) { if (port->port.count) {
pr_debug("gserial_connect: start ttyGS%d\n", port->port_num); pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
gs_start_io(port); gs_start_io(port);
if (gser->connect) if (gser->connect)
...@@ -1315,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser) ...@@ -1315,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
port->port_usb = NULL; port->port_usb = NULL;
gser->ioport = NULL; gser->ioport = NULL;
if (port->open_count > 0 || port->openclose) { if (port->port.count > 0 || port->openclose) {
wake_up_interruptible(&port->drain_wait); wake_up_interruptible(&port->drain_wait);
if (port->port_tty) if (port->port_tty)
tty_hangup(port->port_tty); tty_hangup(port->port_tty);
...@@ -1331,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser) ...@@ -1331,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
/* finally, free any unused/unusable I/O buffers */ /* finally, free any unused/unusable I/O buffers */
spin_lock_irqsave(&port->port_lock, flags); spin_lock_irqsave(&port->port_lock, flags);
if (port->open_count == 0 && !port->openclose) if (port->port.count == 0 && !port->openclose)
gs_buf_free(&port->port_write_buf); gs_buf_free(&port->port_write_buf);
gs_free_requests(gser->out, &port->read_pool, NULL); gs_free_requests(gser->out, &port->read_pool, NULL);
gs_free_requests(gser->out, &port->read_queue, NULL); gs_free_requests(gser->out, &port->read_queue, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment