aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb/hso.c
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2012-04-02 07:54:05 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-09 14:18:36 -0400
commit5ce76e77e0fde4a46bd230d0678099bd648b50d4 (patch)
tree82a4c8fef0a89766c768f165e09a511b25c2047f /drivers/net/usb/hso.c
parentd230788f760043d9c69dbd3928b76f549bff5fb9 (diff)
TTY: hso, add tty_port
And use open count from there. Other members will follow. Remark: port.count is (and never was) properly protected. Only a mutex is held, so ISR and all the functions it calls may see an invalid state. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: Jan Dumon <j.dumon@option.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/net/usb/hso.c')
-rw-r--r--drivers/net/usb/hso.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index cdc589edeaf6..0b26d7532ba4 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -255,9 +255,9 @@ struct hso_serial {
255 u8 dtr_state; 255 u8 dtr_state;
256 unsigned tx_urb_used:1; 256 unsigned tx_urb_used:1;
257 257
258 struct tty_port port;
258 /* from usb_serial_port */ 259 /* from usb_serial_port */
259 struct tty_struct *tty; 260 struct tty_struct *tty;
260 int open_count;
261 spinlock_t serial_lock; 261 spinlock_t serial_lock;
262 262
263 int (*write_data) (struct hso_serial *serial); 263 int (*write_data) (struct hso_serial *serial);
@@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
1190 struct urb *urb; 1190 struct urb *urb;
1191 1191
1192 urb = serial->rx_urb[0]; 1192 urb = serial->rx_urb[0];
1193 if (serial->open_count > 0) { 1193 if (serial->port.count > 0) {
1194 count = put_rxbuf_data(urb, serial); 1194 count = put_rxbuf_data(urb, serial);
1195 if (count == -1) 1195 if (count == -1)
1196 return; 1196 return;
@@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
1226 DUMP1(urb->transfer_buffer, urb->actual_length); 1226 DUMP1(urb->transfer_buffer, urb->actual_length);
1227 1227
1228 /* Anyone listening? */ 1228 /* Anyone listening? */
1229 if (serial->open_count == 0) 1229 if (serial->port.count == 0)
1230 return; 1230 return;
1231 1231
1232 if (status == 0) { 1232 if (status == 0) {
@@ -1311,8 +1311,8 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
1311 spin_unlock_irq(&serial->serial_lock); 1311 spin_unlock_irq(&serial->serial_lock);
1312 1312
1313 /* check for port already opened, if not set the termios */ 1313 /* check for port already opened, if not set the termios */
1314 serial->open_count++; 1314 serial->port.count++;
1315 if (serial->open_count == 1) { 1315 if (serial->port.count == 1) {
1316 serial->rx_state = RX_IDLE; 1316 serial->rx_state = RX_IDLE;
1317 /* Force default termio settings */ 1317 /* Force default termio settings */
1318 _hso_serial_set_termios(tty, NULL); 1318 _hso_serial_set_termios(tty, NULL);
@@ -1324,7 +1324,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
1324 result = hso_start_serial_device(serial->parent, GFP_KERNEL); 1324 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
1325 if (result) { 1325 if (result) {
1326 hso_stop_serial_device(serial->parent); 1326 hso_stop_serial_device(serial->parent);
1327 serial->open_count--; 1327 serial->port.count--;
1328 kref_put(&serial->parent->ref, hso_serial_ref_free); 1328 kref_put(&serial->parent->ref, hso_serial_ref_free);
1329 } 1329 }
1330 } else { 1330 } else {
@@ -1361,10 +1361,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
1361 1361
1362 /* reset the rts and dtr */ 1362 /* reset the rts and dtr */
1363 /* do the actual close */ 1363 /* do the actual close */
1364 serial->open_count--; 1364 serial->port.count--;
1365 1365
1366 if (serial->open_count <= 0) { 1366 if (serial->port.count <= 0) {
1367 serial->open_count = 0; 1367 serial->port.count = 0;
1368 spin_lock_irq(&serial->serial_lock); 1368 spin_lock_irq(&serial->serial_lock);
1369 if (serial->tty == tty) { 1369 if (serial->tty == tty) {
1370 serial->tty->driver_data = NULL; 1370 serial->tty->driver_data = NULL;
@@ -1446,7 +1446,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
1446 1446
1447 /* the actual setup */ 1447 /* the actual setup */
1448 spin_lock_irqsave(&serial->serial_lock, flags); 1448 spin_lock_irqsave(&serial->serial_lock, flags);
1449 if (serial->open_count) 1449 if (serial->port.count)
1450 _hso_serial_set_termios(tty, old); 1450 _hso_serial_set_termios(tty, old);
1451 else 1451 else
1452 tty->termios = old; 1452 tty->termios = old;
@@ -1905,7 +1905,7 @@ static void intr_callback(struct urb *urb)
1905 D1("Pending read interrupt on port %d\n", i); 1905 D1("Pending read interrupt on port %d\n", i);
1906 spin_lock(&serial->serial_lock); 1906 spin_lock(&serial->serial_lock);
1907 if (serial->rx_state == RX_IDLE && 1907 if (serial->rx_state == RX_IDLE &&
1908 serial->open_count > 0) { 1908 serial->port.count > 0) {
1909 /* Setup and send a ctrl req read on 1909 /* Setup and send a ctrl req read on
1910 * port i */ 1910 * port i */
1911 if (!serial->rx_urb_filled[0]) { 1911 if (!serial->rx_urb_filled[0]) {
@@ -2320,6 +2320,7 @@ static int hso_serial_common_create(struct hso_serial *serial, int num_urbs,
2320 serial->minor = minor; 2320 serial->minor = minor;
2321 serial->magic = HSO_SERIAL_MAGIC; 2321 serial->magic = HSO_SERIAL_MAGIC;
2322 spin_lock_init(&serial->serial_lock); 2322 spin_lock_init(&serial->serial_lock);
2323 tty_port_init(&serial->port);
2323 serial->num_rx_urbs = num_urbs; 2324 serial->num_rx_urbs = num_urbs;
2324 2325
2325 /* RX, allocate urb and initialize */ 2326 /* RX, allocate urb and initialize */
@@ -3098,7 +3099,7 @@ static int hso_resume(struct usb_interface *iface)
3098 /* Start all serial ports */ 3099 /* Start all serial ports */
3099 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { 3100 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
3100 if (serial_table[i] && (serial_table[i]->interface == iface)) { 3101 if (serial_table[i] && (serial_table[i]->interface == iface)) {
3101 if (dev2ser(serial_table[i])->open_count) { 3102 if (dev2ser(serial_table[i])->port.count) {
3102 result = 3103 result =
3103 hso_start_serial_device(serial_table[i], GFP_NOIO); 3104 hso_start_serial_device(serial_table[i], GFP_NOIO);
3104 hso_kick_transmit(dev2ser(serial_table[i])); 3105 hso_kick_transmit(dev2ser(serial_table[i]));