aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb/hso.c
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2012-04-02 07:54:07 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-09 14:18:36 -0400
commit9f8c0b081daff1dbf9ca889560bf25aef0a75207 (patch)
treea3461d2c5af87afcb8294656dc9cf0c685a57a2e /drivers/net/usb/hso.c
parent30409420d2e181215745fdc7052446b439e0221f (diff)
TTY: hso, use tty from tty_port
We switched tty refcounting there to the one provided by tty_port helpers. So tty_port->tty is now protected by tty_port->lock, not by hso_serial->serial_lock. Side note: tty->driver_data does not need the lock, so it is needed neither in open, nor in close paths. 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.c40
1 files changed, 13 insertions, 27 deletions
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index ec782c7eabd8..813d70946d39 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -250,7 +250,6 @@ struct hso_serial {
250 250
251 struct tty_port port; 251 struct tty_port port;
252 /* from usb_serial_port */ 252 /* from usb_serial_port */
253 struct tty_struct *tty;
254 spinlock_t serial_lock; 253 spinlock_t serial_lock;
255 254
256 int (*write_data) (struct hso_serial *serial); 255 int (*write_data) (struct hso_serial *serial);
@@ -1297,11 +1296,8 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
1297 kref_get(&serial->parent->ref); 1296 kref_get(&serial->parent->ref);
1298 1297
1299 /* setup */ 1298 /* setup */
1300 spin_lock_irq(&serial->serial_lock);
1301 tty->driver_data = serial; 1299 tty->driver_data = serial;
1302 tty_kref_put(serial->tty); 1300 tty_port_tty_set(&serial->port, tty);
1303 serial->tty = tty_kref_get(tty);
1304 spin_unlock_irq(&serial->serial_lock);
1305 1301
1306 /* check for port already opened, if not set the termios */ 1302 /* check for port already opened, if not set the termios */
1307 serial->port.count++; 1303 serial->port.count++;
@@ -1358,13 +1354,7 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
1358 1354
1359 if (serial->port.count <= 0) { 1355 if (serial->port.count <= 0) {
1360 serial->port.count = 0; 1356 serial->port.count = 0;
1361 spin_lock_irq(&serial->serial_lock); 1357 tty_port_tty_set(&serial->port, NULL);
1362 if (serial->tty == tty) {
1363 serial->tty->driver_data = NULL;
1364 serial->tty = NULL;
1365 tty_kref_put(tty);
1366 }
1367 spin_unlock_irq(&serial->serial_lock);
1368 if (!usb_gone) 1358 if (!usb_gone)
1369 hso_stop_serial_device(serial->parent); 1359 hso_stop_serial_device(serial->parent);
1370 tasklet_kill(&serial->unthrottle_tasklet); 1360 tasklet_kill(&serial->unthrottle_tasklet);
@@ -1947,14 +1937,13 @@ static void hso_std_serial_write_bulk_callback(struct urb *urb)
1947 1937
1948 spin_lock(&serial->serial_lock); 1938 spin_lock(&serial->serial_lock);
1949 serial->tx_urb_used = 0; 1939 serial->tx_urb_used = 0;
1950 tty = tty_kref_get(serial->tty);
1951 spin_unlock(&serial->serial_lock); 1940 spin_unlock(&serial->serial_lock);
1952 if (status) { 1941 if (status) {
1953 handle_usb_error(status, __func__, serial->parent); 1942 handle_usb_error(status, __func__, serial->parent);
1954 tty_kref_put(tty);
1955 return; 1943 return;
1956 } 1944 }
1957 hso_put_activity(serial->parent); 1945 hso_put_activity(serial->parent);
1946 tty = tty_port_tty_get(&serial->port);
1958 if (tty) { 1947 if (tty) {
1959 tty_wakeup(tty); 1948 tty_wakeup(tty);
1960 tty_kref_put(tty); 1949 tty_kref_put(tty);
@@ -1994,7 +1983,6 @@ static void ctrl_callback(struct urb *urb)
1994 struct hso_serial *serial = urb->context; 1983 struct hso_serial *serial = urb->context;
1995 struct usb_ctrlrequest *req; 1984 struct usb_ctrlrequest *req;
1996 int status = urb->status; 1985 int status = urb->status;
1997 struct tty_struct *tty;
1998 1986
1999 /* sanity check */ 1987 /* sanity check */
2000 if (!serial) 1988 if (!serial)
@@ -2002,11 +1990,9 @@ static void ctrl_callback(struct urb *urb)
2002 1990
2003 spin_lock(&serial->serial_lock); 1991 spin_lock(&serial->serial_lock);
2004 serial->tx_urb_used = 0; 1992 serial->tx_urb_used = 0;
2005 tty = tty_kref_get(serial->tty);
2006 spin_unlock(&serial->serial_lock); 1993 spin_unlock(&serial->serial_lock);
2007 if (status) { 1994 if (status) {
2008 handle_usb_error(status, __func__, serial->parent); 1995 handle_usb_error(status, __func__, serial->parent);
2009 tty_kref_put(tty);
2010 return; 1996 return;
2011 } 1997 }
2012 1998
@@ -2024,13 +2010,15 @@ static void ctrl_callback(struct urb *urb)
2024 put_rxbuf_data_and_resubmit_ctrl_urb(serial); 2010 put_rxbuf_data_and_resubmit_ctrl_urb(serial);
2025 spin_unlock(&serial->serial_lock); 2011 spin_unlock(&serial->serial_lock);
2026 } else { 2012 } else {
2013 struct tty_struct *tty = tty_port_tty_get(&serial->port);
2027 hso_put_activity(serial->parent); 2014 hso_put_activity(serial->parent);
2028 if (tty) 2015 if (tty) {
2029 tty_wakeup(tty); 2016 tty_wakeup(tty);
2017 tty_kref_put(tty);
2018 }
2030 /* response to a write command */ 2019 /* response to a write command */
2031 hso_kick_transmit(serial); 2020 hso_kick_transmit(serial);
2032 } 2021 }
2033 tty_kref_put(tty);
2034} 2022}
2035 2023
2036/* handle RX data for serial port */ 2024/* handle RX data for serial port */
@@ -2046,8 +2034,7 @@ static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial)
2046 return -2; 2034 return -2;
2047 } 2035 }
2048 2036
2049 /* All callers to put_rxbuf_data hold serial_lock */ 2037 tty = tty_port_tty_get(&serial->port);
2050 tty = tty_kref_get(serial->tty);
2051 2038
2052 /* Push data to tty */ 2039 /* Push data to tty */
2053 if (tty) { 2040 if (tty) {
@@ -2067,12 +2054,12 @@ static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial)
2067 write_length_remaining -= curr_write_len; 2054 write_length_remaining -= curr_write_len;
2068 tty_flip_buffer_push(tty); 2055 tty_flip_buffer_push(tty);
2069 } 2056 }
2057 tty_kref_put(tty);
2070 } 2058 }
2071 if (write_length_remaining == 0) { 2059 if (write_length_remaining == 0) {
2072 serial->curr_rx_urb_offset = 0; 2060 serial->curr_rx_urb_offset = 0;
2073 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; 2061 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0;
2074 } 2062 }
2075 tty_kref_put(tty);
2076 return write_length_remaining; 2063 return write_length_remaining;
2077} 2064}
2078 2065
@@ -3166,13 +3153,12 @@ static void hso_free_interface(struct usb_interface *interface)
3166 if (serial_table[i] && 3153 if (serial_table[i] &&
3167 (serial_table[i]->interface == interface)) { 3154 (serial_table[i]->interface == interface)) {
3168 hso_dev = dev2ser(serial_table[i]); 3155 hso_dev = dev2ser(serial_table[i]);
3169 spin_lock_irq(&hso_dev->serial_lock); 3156 tty = tty_port_tty_get(&hso_dev->port);
3170 tty = tty_kref_get(hso_dev->tty); 3157 if (tty) {
3171 spin_unlock_irq(&hso_dev->serial_lock);
3172 if (tty)
3173 tty_hangup(tty); 3158 tty_hangup(tty);
3159 tty_kref_put(tty);
3160 }
3174 mutex_lock(&hso_dev->parent->mutex); 3161 mutex_lock(&hso_dev->parent->mutex);
3175 tty_kref_put(tty);
3176 hso_dev->parent->usb_gone = 1; 3162 hso_dev->parent->usb_gone = 1;
3177 mutex_unlock(&hso_dev->parent->mutex); 3163 mutex_unlock(&hso_dev->parent->mutex);
3178 kref_put(&serial_table[i]->ref, hso_serial_ref_free); 3164 kref_put(&serial_table[i]->ref, hso_serial_ref_free);