USB: remove references to port->port.count from the serial drivers

This patch (as1344) removes references to port->port.count from the
USB serial drivers.  Now that serial ports are properly reference
counted, port.count checking is unnecessary and incorrect.  Drivers
should assume that the port is in use from the time the open method
runs until the close method is called.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Alan Stern 2010-02-17 10:05:47 -05:00 коммит произвёл Greg Kroah-Hartman
Родитель a108bfcb37
Коммит 1f87158e44
11 изменённых файлов: 65 добавлений и 125 удалений

Просмотреть файл

@ -468,10 +468,6 @@ static void aircable_read_bulk_callback(struct urb *urb)
if (status) { if (status) {
dbg("%s - urb status = %d", __func__, status); dbg("%s - urb status = %d", __func__, status);
if (!port->port.count) {
dbg("%s - port is closed, exiting.", __func__);
return;
}
if (status == -EPROTO) { if (status == -EPROTO) {
dbg("%s - caught -EPROTO, resubmitting the urb", dbg("%s - caught -EPROTO, resubmitting the urb",
__func__); __func__);
@ -530,8 +526,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
} }
tty_kref_put(tty); tty_kref_put(tty);
/* Schedule the next read _if_ we are still open */ /* Schedule the next read */
if (port->port.count) {
usb_fill_bulk_urb(port->read_urb, port->serial->dev, usb_fill_bulk_urb(port->read_urb, port->serial->dev,
usb_rcvbulkpipe(port->serial->dev, usb_rcvbulkpipe(port->serial->dev,
port->bulk_in_endpointAddress), port->bulk_in_endpointAddress),
@ -540,13 +535,10 @@ static void aircable_read_bulk_callback(struct urb *urb)
aircable_read_bulk_callback, port); aircable_read_bulk_callback, port);
result = usb_submit_urb(urb, GFP_ATOMIC); result = usb_submit_urb(urb, GFP_ATOMIC);
if (result) if (result && result != -EPERM)
dev_err(&urb->dev->dev, dev_err(&urb->dev->dev,
"%s - failed resubmitting read urb, error %d\n", "%s - failed resubmitting read urb, error %d\n",
__func__, result); __func__, result);
}
return;
} }
/* Based on ftdi_sio.c throttle */ /* Based on ftdi_sio.c throttle */

Просмотреть файл

@ -1321,9 +1321,9 @@ static void cypress_read_int_callback(struct urb *urb)
continue_read: continue_read:
tty_kref_put(tty); tty_kref_put(tty);
/* Continue trying to always read... unless the port has closed. */ /* Continue trying to always read */
if (port->port.count > 0 && priv->comm_is_ok) { if (priv->comm_is_ok) {
usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
usb_rcvintpipe(port->serial->dev, usb_rcvintpipe(port->serial->dev,
port->interrupt_in_endpointAddress), port->interrupt_in_endpointAddress),
@ -1332,7 +1332,7 @@ continue_read:
cypress_read_int_callback, port, cypress_read_int_callback, port,
priv->read_urb_interval); priv->read_urb_interval);
result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
if (result) { if (result && result != -EPERM) {
dev_err(&urb->dev->dev, "%s - failed resubmitting " dev_err(&urb->dev->dev, "%s - failed resubmitting "
"read urb, error %d\n", __func__, "read urb, error %d\n", __func__,
result); result);

Просмотреть файл

@ -1262,10 +1262,10 @@ static void digi_write_bulk_callback(struct urb *urb)
return; return;
} }
/* try to send any buffered data on this port, if it is open */ /* try to send any buffered data on this port */
spin_lock(&priv->dp_port_lock); spin_lock(&priv->dp_port_lock);
priv->dp_write_urb_in_use = 0; priv->dp_write_urb_in_use = 0;
if (port->port.count && priv->dp_out_buf_len > 0) { if (priv->dp_out_buf_len > 0) {
*((unsigned char *)(port->write_urb->transfer_buffer)) *((unsigned char *)(port->write_urb->transfer_buffer))
= (unsigned char)DIGI_CMD_SEND_DATA; = (unsigned char)DIGI_CMD_SEND_DATA;
*((unsigned char *)(port->write_urb->transfer_buffer) + 1) *((unsigned char *)(port->write_urb->transfer_buffer) + 1)
@ -1288,7 +1288,7 @@ static void digi_write_bulk_callback(struct urb *urb)
schedule_work(&priv->dp_wakeup_work); schedule_work(&priv->dp_wakeup_work);
spin_unlock(&priv->dp_port_lock); spin_unlock(&priv->dp_port_lock);
if (ret) if (ret && ret != -EPERM)
dev_err(&port->dev, dev_err(&port->dev,
"%s: usb_submit_urb failed, ret=%d, port=%d\n", "%s: usb_submit_urb failed, ret=%d, port=%d\n",
__func__, ret, priv->dp_port_num); __func__, ret, priv->dp_port_num);
@ -1353,8 +1353,7 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port)
struct digi_port *priv = usb_get_serial_port_data(port); struct digi_port *priv = usb_get_serial_port_data(port);
struct ktermios not_termios; struct ktermios not_termios;
dbg("digi_open: TOP: port=%d, open_count=%d", dbg("digi_open: TOP: port=%d", priv->dp_port_num);
priv->dp_port_num, port->port.count);
/* be sure the device is started up */ /* be sure the device is started up */
if (digi_startup_device(port->serial) != 0) if (digi_startup_device(port->serial) != 0)
@ -1393,8 +1392,7 @@ static void digi_close(struct usb_serial_port *port)
unsigned char buf[32]; unsigned char buf[32];
struct digi_port *priv = usb_get_serial_port_data(port); struct digi_port *priv = usb_get_serial_port_data(port);
dbg("digi_close: TOP: port=%d, open_count=%d", dbg("digi_close: TOP: port=%d", priv->dp_port_num);
priv->dp_port_num, port->port.count);
mutex_lock(&port->serial->disc_mutex); mutex_lock(&port->serial->disc_mutex);
/* if disconnected, just clear flags */ /* if disconnected, just clear flags */
@ -1629,7 +1627,7 @@ static void digi_read_bulk_callback(struct urb *urb)
/* continue read */ /* continue read */
urb->dev = port->serial->dev; urb->dev = port->serial->dev;
ret = usb_submit_urb(urb, GFP_ATOMIC); ret = usb_submit_urb(urb, GFP_ATOMIC);
if (ret != 0) { if (ret != 0 && ret != -EPERM) {
dev_err(&port->dev, dev_err(&port->dev,
"%s: failed resubmitting urb, ret=%d, port=%d\n", "%s: failed resubmitting urb, ret=%d, port=%d\n",
__func__, ret, priv->dp_port_num); __func__, ret, priv->dp_port_num);
@ -1662,7 +1660,7 @@ static int digi_read_inb_callback(struct urb *urb)
/* do not process callbacks on closed ports */ /* do not process callbacks on closed ports */
/* but do continue the read chain */ /* but do continue the read chain */
if (port->port.count == 0) if (urb->status == -ENOENT)
return 0; return 0;
/* short/multiple packet check */ /* short/multiple packet check */
@ -1767,7 +1765,6 @@ static int digi_read_oob_callback(struct urb *urb)
tty = tty_port_tty_get(&port->port); tty = tty_port_tty_get(&port->port);
rts = 0; rts = 0;
if (port->port.count)
rts = tty->termios->c_cflag & CRTSCTS; rts = tty->termios->c_cflag & CRTSCTS;
if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) { if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) {

Просмотреть файл

@ -20,6 +20,7 @@
#include <linux/usb/serial.h> #include <linux/usb/serial.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/kfifo.h> #include <linux/kfifo.h>
#include <linux/serial.h>
static int debug; static int debug;
@ -585,7 +586,7 @@ int usb_serial_generic_resume(struct usb_serial *serial)
for (i = 0; i < serial->num_ports; i++) { for (i = 0; i < serial->num_ports; i++) {
port = serial->port[i]; port = serial->port[i];
if (!port->port.count) if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags))
continue; continue;
if (port->read_urb) { if (port->read_urb) {

Просмотреть файл

@ -445,11 +445,6 @@ static void ir_read_bulk_callback(struct urb *urb)
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
if (!port->port.count) {
dbg("%s - port closed.", __func__);
return;
}
switch (status) { switch (status) {
case 0: /* Successful */ case 0: /* Successful */
/* /*

Просмотреть файл

@ -464,13 +464,9 @@ static void usa26_indat_callback(struct urb *urb)
/* Resubmit urb so we continue receiving */ /* Resubmit urb so we continue receiving */
urb->dev = port->serial->dev; urb->dev = port->serial->dev;
if (port->port.count) {
err = usb_submit_urb(urb, GFP_ATOMIC); err = usb_submit_urb(urb, GFP_ATOMIC);
if (err != 0) if (err != 0)
dbg("%s - resubmit read urb failed. (%d)", dbg("%s - resubmit read urb failed. (%d)", __func__, err);
__func__, err);
}
return;
} }
/* Outdat handling is common for all devices */ /* Outdat handling is common for all devices */
@ -483,7 +479,6 @@ static void usa2x_outdat_callback(struct urb *urb)
p_priv = usb_get_serial_port_data(port); p_priv = usb_get_serial_port_data(port);
dbg("%s - urb %d", __func__, urb == p_priv->out_urbs[1]); dbg("%s - urb %d", __func__, urb == p_priv->out_urbs[1]);
if (port->port.count)
usb_serial_port_softint(port); usb_serial_port_softint(port);
} }
@ -615,12 +610,10 @@ static void usa28_indat_callback(struct urb *urb)
/* Resubmit urb so we continue receiving */ /* Resubmit urb so we continue receiving */
urb->dev = port->serial->dev; urb->dev = port->serial->dev;
if (port->port.count) {
err = usb_submit_urb(urb, GFP_ATOMIC); err = usb_submit_urb(urb, GFP_ATOMIC);
if (err != 0) if (err != 0)
dbg("%s - resubmit read urb failed. (%d)", dbg("%s - resubmit read urb failed. (%d)",
__func__, err); __func__, err);
}
p_priv->in_flip ^= 1; p_priv->in_flip ^= 1;
urb = p_priv->in_urbs[p_priv->in_flip]; urb = p_priv->in_urbs[p_priv->in_flip];
@ -856,12 +849,9 @@ static void usa49_indat_callback(struct urb *urb)
/* Resubmit urb so we continue receiving */ /* Resubmit urb so we continue receiving */
urb->dev = port->serial->dev; urb->dev = port->serial->dev;
if (port->port.count) {
err = usb_submit_urb(urb, GFP_ATOMIC); err = usb_submit_urb(urb, GFP_ATOMIC);
if (err != 0) if (err != 0)
dbg("%s - resubmit read urb failed. (%d)", dbg("%s - resubmit read urb failed. (%d)", __func__, err);
__func__, err);
}
} }
static void usa49wg_indat_callback(struct urb *urb) static void usa49wg_indat_callback(struct urb *urb)
@ -904,11 +894,7 @@ static void usa49wg_indat_callback(struct urb *urb)
/* no error on any byte */ /* no error on any byte */
i++; i++;
for (x = 1; x < len ; ++x) for (x = 1; x < len ; ++x)
if (port->port.count) tty_insert_flip_char(tty, data[i++], 0);
tty_insert_flip_char(tty,
data[i++], 0);
else
i++;
} else { } else {
/* /*
* some bytes had errors, every byte has status * some bytes had errors, every byte has status
@ -922,13 +908,11 @@ static void usa49wg_indat_callback(struct urb *urb)
if (stat & RXERROR_PARITY) if (stat & RXERROR_PARITY)
flag |= TTY_PARITY; flag |= TTY_PARITY;
/* XXX should handle break (0x10) */ /* XXX should handle break (0x10) */
if (port->port.count)
tty_insert_flip_char(tty, tty_insert_flip_char(tty,
data[i+1], flag); data[i+1], flag);
i += 2; i += 2;
} }
} }
if (port->port.count)
tty_flip_buffer_push(tty); tty_flip_buffer_push(tty);
tty_kref_put(tty); tty_kref_put(tty);
} }
@ -1013,13 +997,9 @@ static void usa90_indat_callback(struct urb *urb)
/* Resubmit urb so we continue receiving */ /* Resubmit urb so we continue receiving */
urb->dev = port->serial->dev; urb->dev = port->serial->dev;
if (port->port.count) {
err = usb_submit_urb(urb, GFP_ATOMIC); err = usb_submit_urb(urb, GFP_ATOMIC);
if (err != 0) if (err != 0)
dbg("%s - resubmit read urb failed. (%d)", dbg("%s - resubmit read urb failed. (%d)", __func__, err);
__func__, err);
}
return;
} }
@ -2418,7 +2398,6 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
msg.portEnabled = 0; msg.portEnabled = 0;
/* Sending intermediate configs */ /* Sending intermediate configs */
else { else {
if (port->port.count)
msg.portEnabled = 1; msg.portEnabled = 1;
msg.txBreak = (p_priv->break_on); msg.txBreak = (p_priv->break_on);
} }

Просмотреть файл

@ -971,9 +971,9 @@ static void option_indat_callback(struct urb *urb)
tty_kref_put(tty); tty_kref_put(tty);
/* Resubmit urb so we continue receiving */ /* Resubmit urb so we continue receiving */
if (port->port.count && status != -ESHUTDOWN) { if (status != -ESHUTDOWN) {
err = usb_submit_urb(urb, GFP_ATOMIC); err = usb_submit_urb(urb, GFP_ATOMIC);
if (err) if (err && err != -EPERM)
printk(KERN_ERR "%s: resubmit read urb failed. " printk(KERN_ERR "%s: resubmit read urb failed. "
"(%d)", __func__, err); "(%d)", __func__, err);
else else

Просмотреть файл

@ -585,9 +585,6 @@ static int oti6858_open(struct tty_struct *tty, struct usb_serial_port *port)
usb_clear_halt(serial->dev, port->write_urb->pipe); usb_clear_halt(serial->dev, port->write_urb->pipe);
usb_clear_halt(serial->dev, port->read_urb->pipe); usb_clear_halt(serial->dev, port->read_urb->pipe);
if (port->port.count != 1)
return 0;
buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL); buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL);
if (buf == NULL) { if (buf == NULL) {
dev_err(&port->dev, "%s(): out of memory!\n", __func__); dev_err(&port->dev, "%s(): out of memory!\n", __func__);
@ -934,10 +931,6 @@ static void oti6858_read_bulk_callback(struct urb *urb)
spin_unlock_irqrestore(&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
if (status != 0) { if (status != 0) {
if (!port->port.count) {
dbg("%s(): port is closed, exiting", __func__);
return;
}
/* /*
if (status == -EPROTO) { if (status == -EPROTO) {
* PL2303 mysteriously fails with -EPROTO reschedule * PL2303 mysteriously fails with -EPROTO reschedule
@ -961,15 +954,13 @@ static void oti6858_read_bulk_callback(struct urb *urb)
} }
tty_kref_put(tty); tty_kref_put(tty);
/* schedule the interrupt urb if we are still open */ /* schedule the interrupt urb */
if (port->port.count != 0) {
port->interrupt_in_urb->dev = port->serial->dev; port->interrupt_in_urb->dev = port->serial->dev;
result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
if (result != 0) { if (result != 0 && result != -EPERM) {
dev_err(&port->dev, "%s(): usb_submit_urb() failed," dev_err(&port->dev, "%s(): usb_submit_urb() failed,"
" error %d\n", __func__, result); " error %d\n", __func__, result);
} }
}
} }
static void oti6858_write_bulk_callback(struct urb *urb) static void oti6858_write_bulk_callback(struct urb *urb)

Просмотреть файл

@ -1071,10 +1071,6 @@ static void pl2303_read_bulk_callback(struct urb *urb)
if (status) { if (status) {
dbg("%s - urb status = %d", __func__, status); dbg("%s - urb status = %d", __func__, status);
if (!port->port.count) {
dbg("%s - port is closed, exiting.", __func__);
return;
}
if (status == -EPROTO) { if (status == -EPROTO) {
/* PL2303 mysteriously fails with -EPROTO reschedule /* PL2303 mysteriously fails with -EPROTO reschedule
* the read */ * the read */
@ -1107,15 +1103,11 @@ static void pl2303_read_bulk_callback(struct urb *urb)
} }
tty_kref_put(tty); tty_kref_put(tty);
/* Schedule the next read _if_ we are still open */ /* Schedule the next read _if_ we are still open */
if (port->port.count) {
urb->dev = port->serial->dev; urb->dev = port->serial->dev;
result = usb_submit_urb(urb, GFP_ATOMIC); result = usb_submit_urb(urb, GFP_ATOMIC);
if (result) if (result && result != -EPERM)
dev_err(&urb->dev->dev, "%s - failed resubmitting" dev_err(&urb->dev->dev, "%s - failed resubmitting"
" read urb, error %d\n", __func__, result); " read urb, error %d\n", __func__, result);
}
return;
} }
static void pl2303_write_bulk_callback(struct urb *urb) static void pl2303_write_bulk_callback(struct urb *urb)

Просмотреть файл

@ -610,10 +610,10 @@ static void sierra_indat_callback(struct urb *urb)
} }
/* Resubmit urb so we continue receiving */ /* Resubmit urb so we continue receiving */
if (port->port.count && status != -ESHUTDOWN && status != -EPERM) { if (status != -ESHUTDOWN && status != -EPERM) {
usb_mark_last_busy(port->serial->dev); usb_mark_last_busy(port->serial->dev);
err = usb_submit_urb(urb, GFP_ATOMIC); err = usb_submit_urb(urb, GFP_ATOMIC);
if (err) if (err && err != -EPERM)
dev_err(&port->dev, "resubmit read urb failed." dev_err(&port->dev, "resubmit read urb failed."
"(%d)\n", err); "(%d)\n", err);
} }
@ -672,11 +672,11 @@ static void sierra_instat_callback(struct urb *urb)
dev_dbg(&port->dev, "%s: error %d\n", __func__, status); dev_dbg(&port->dev, "%s: error %d\n", __func__, status);
/* Resubmit urb so we continue receiving IRQ data */ /* Resubmit urb so we continue receiving IRQ data */
if (port->port.count && status != -ESHUTDOWN && status != -ENOENT) { if (status != -ESHUTDOWN && status != -ENOENT) {
usb_mark_last_busy(serial->dev); usb_mark_last_busy(serial->dev);
urb->dev = serial->dev; urb->dev = serial->dev;
err = usb_submit_urb(urb, GFP_ATOMIC); err = usb_submit_urb(urb, GFP_ATOMIC);
if (err) if (err && err != -EPERM)
dev_err(&port->dev, "%s: resubmit intr urb " dev_err(&port->dev, "%s: resubmit intr urb "
"failed. (%d)\n", __func__, err); "failed. (%d)\n", __func__, err);
} }

Просмотреть файл

@ -686,8 +686,6 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
/* check the urb status */ /* check the urb status */
if (result) { if (result) {
if (!port->port.count)
return;
if (result == -EPROTO) { if (result == -EPROTO) {
/* spcp8x5 mysteriously fails with -EPROTO */ /* spcp8x5 mysteriously fails with -EPROTO */
/* reschedule the read */ /* reschedule the read */
@ -734,16 +732,11 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
} }
tty_kref_put(tty); tty_kref_put(tty);
/* Schedule the next read _if_ we are still open */ /* Schedule the next read */
if (port->port.count) {
urb->dev = port->serial->dev; urb->dev = port->serial->dev;
result = usb_submit_urb(urb , GFP_ATOMIC); result = usb_submit_urb(urb , GFP_ATOMIC);
if (result) if (result)
dev_dbg(&port->dev, "failed submitting read urb %d\n", dev_dbg(&port->dev, "failed submitting read urb %d\n", result);
result);
}
return;
} }
/* get data from ring buffer and then write to usb bus */ /* get data from ring buffer and then write to usb bus */