From 2e124b4a390ca85325fae75764bef92f0547fa25 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Thu, 3 Jan 2013 15:53:06 +0100 Subject: [PATCH] TTY: switch tty_flip_buffer_push Now, we start converting tty buffer functions to actually use tty_port. This will allow us to get rid of the need of tty in many call sites. Only tty_port will needed and hence no more tty_port_tty_get in those paths. Now, the one where most of tty_port_tty_get gets removed: tty_flip_buffer_push. IOW we also closed all the races in drivers not using tty_port_tty_get at all yet. Also we move tty_flip_buffer_push declaration from include/linux/tty.h to include/linux/tty_flip.h to all others while we are changing it anyway. Signed-off-by: Jiri Slaby Signed-off-by: Greg Kroah-Hartman [[ stefanr: only staging/fwserial bits included here ]] --- arch/ia64/hp/sim/simserial.c | 18 ++------- arch/mn10300/kernel/mn10300-serial.c | 7 ++-- arch/parisc/kernel/pdc_cons.c | 8 +--- arch/um/drivers/chan.h | 3 +- arch/um/drivers/chan_kern.c | 14 +++---- arch/um/drivers/line.c | 7 ++-- arch/xtensa/platforms/iss/console.c | 9 ++--- drivers/char/pcmcia/synclink_cs.c | 14 ++----- drivers/ipack/devices/ipoctal.c | 14 ++----- drivers/isdn/gigaset/interface.c | 10 +---- drivers/isdn/i4l/isdn_tty.c | 39 ++++++++----------- drivers/mmc/card/sdio_uart.c | 14 ++----- drivers/net/usb/hso.c | 31 ++++++++------- drivers/s390/char/con3215.c | 4 +- drivers/s390/char/sclp_tty.c | 4 +- drivers/s390/char/sclp_vt220.c | 8 +--- drivers/staging/ccg/u_serial.c | 11 ++---- drivers/staging/dgrp/dgrp_net_ops.c | 4 +- drivers/staging/fwserial/fwserial.c | 41 ++++++++------------ drivers/staging/serqt_usb2/serqt_usb2.c | 9 ++--- drivers/tty/amiserial.c | 5 +-- drivers/tty/bfin_jtag_comm.c | 22 +++++------ drivers/tty/ehv_bytechan.c | 9 +---- drivers/tty/hvc/hvc_console.c | 2 +- drivers/tty/hvc/hvcs.c | 2 +- drivers/tty/hvc/hvsi.c | 6 +-- drivers/tty/ipwireless/tty.c | 8 +--- drivers/tty/isicom.c | 4 +- drivers/tty/mxser.c | 2 +- drivers/tty/n_gsm.c | 58 ++++++++++++++--------------- drivers/tty/nozomi.c | 14 +++---- drivers/tty/pty.c | 2 +- drivers/tty/rocket.c | 25 ++++++------- drivers/tty/serial/21285.c | 3 +- drivers/tty/serial/8250/8250.c | 3 +- drivers/tty/serial/altera_jtaguart.c | 2 +- drivers/tty/serial/altera_uart.c | 2 +- drivers/tty/serial/amba-pl010.c | 3 +- drivers/tty/serial/amba-pl011.c | 7 +--- drivers/tty/serial/apbuart.c | 3 +- drivers/tty/serial/ar933x_uart.c | 7 +--- drivers/tty/serial/arc_uart.c | 8 +--- drivers/tty/serial/atmel_serial.c | 5 +-- drivers/tty/serial/bcm63xx_uart.c | 4 +- drivers/tty/serial/bfin_sport_uart.c | 4 +- drivers/tty/serial/bfin_uart.c | 10 ++--- drivers/tty/serial/clps711x.c | 8 +--- drivers/tty/serial/cpm_uart/cpm_uart_core.c | 3 +- drivers/tty/serial/crisv10.c | 17 +-------- drivers/tty/serial/dz.c | 4 +- drivers/tty/serial/efm32-uart.c | 8 +--- drivers/tty/serial/icom.c | 3 +- drivers/tty/serial/ifx6x60.c | 6 +-- drivers/tty/serial/imx.c | 3 +- drivers/tty/serial/ioc3_serial.c | 6 +-- drivers/tty/serial/ioc4_serial.c | 6 +-- drivers/tty/serial/jsm/jsm_tty.c | 2 +- drivers/tty/serial/kgdb_nmi.c | 10 +---- drivers/tty/serial/lantiq.c | 15 +++----- drivers/tty/serial/lpc32xx_hs.c | 16 +------- drivers/tty/serial/m32r_sio.c | 3 +- drivers/tty/serial/max3100.c | 8 ++-- drivers/tty/serial/max310x.c | 8 +--- drivers/tty/serial/mcf.c | 2 +- drivers/tty/serial/mfd.c | 12 +----- drivers/tty/serial/mpc52xx_uart.c | 3 +- drivers/tty/serial/mpsc.c | 5 +-- drivers/tty/serial/mrst_max3110.c | 11 +----- drivers/tty/serial/msm_serial.c | 6 +-- drivers/tty/serial/msm_serial_hs.c | 3 +- drivers/tty/serial/msm_smd_tty.c | 2 +- drivers/tty/serial/mux.c | 6 +-- drivers/tty/serial/mxs-auart.c | 6 +-- drivers/tty/serial/netx-serial.c | 4 +- drivers/tty/serial/nwpserial.c | 3 +- drivers/tty/serial/omap-serial.c | 3 +- drivers/tty/serial/pch_uart.c | 19 +--------- drivers/tty/serial/pmac_zilog.c | 30 +++++++-------- drivers/tty/serial/pnx8xxx_uart.c | 3 +- drivers/tty/serial/pxa.c | 3 +- drivers/tty/serial/sa1100.c | 3 +- drivers/tty/serial/samsung.c | 3 +- drivers/tty/serial/sb1250-duart.c | 2 +- drivers/tty/serial/sc26xx.c | 27 ++++++-------- drivers/tty/serial/sccnxp.c | 8 +--- drivers/tty/serial/serial_ks8695.c | 3 +- drivers/tty/serial/serial_txx9.c | 3 +- drivers/tty/serial/sh-sci.c | 18 +++------ drivers/tty/serial/sirfsoc_uart.c | 8 +--- drivers/tty/serial/sn_console.c | 12 ++---- drivers/tty/serial/sunhv.c | 16 ++++---- drivers/tty/serial/sunsab.c | 20 ++++------ drivers/tty/serial/sunsu.c | 13 ++----- drivers/tty/serial/sunzilog.c | 28 ++++++-------- drivers/tty/serial/timbuart.c | 2 +- drivers/tty/serial/uartlite.c | 2 +- drivers/tty/serial/ucc_uart.c | 3 +- drivers/tty/serial/vr41xx_siu.c | 4 +- drivers/tty/serial/vt8500_serial.c | 12 +----- drivers/tty/serial/xilinx_uartps.c | 14 ++----- drivers/tty/serial/zs.c | 2 +- drivers/tty/synclink.c | 5 +-- drivers/tty/synclink_gt.c | 5 +-- drivers/tty/synclinkmp.c | 4 +- drivers/tty/tty_buffer.c | 8 ++-- drivers/usb/class/cdc-acm.c | 10 +---- drivers/usb/gadget/u_serial.c | 4 +- drivers/usb/serial/aircable.c | 8 +--- drivers/usb/serial/ark3116.c | 8 +--- drivers/usb/serial/belkin_sa.c | 8 +--- drivers/usb/serial/cyberjack.c | 9 +---- drivers/usb/serial/cypress_m8.c | 4 +- drivers/usb/serial/digi_acceleport.c | 8 +--- drivers/usb/serial/f81232.c | 8 +--- drivers/usb/serial/ftdi_sio.c | 8 +--- drivers/usb/serial/garmin_gps.c | 7 +--- drivers/usb/serial/generic.c | 8 +--- drivers/usb/serial/io_edgeport.c | 35 +++++++---------- drivers/usb/serial/io_ti.c | 27 +++++--------- drivers/usb/serial/ir-usb.c | 7 +--- drivers/usb/serial/iuu_phoenix.c | 7 +--- drivers/usb/serial/keyspan.c | 31 ++++----------- drivers/usb/serial/keyspan_pda.c | 7 +--- drivers/usb/serial/kl5kusb105.c | 8 +--- drivers/usb/serial/kobil_sct.c | 7 +--- drivers/usb/serial/mct_u232.c | 11 ++---- drivers/usb/serial/metro-usb.c | 7 +--- drivers/usb/serial/mos7720.c | 7 +--- drivers/usb/serial/mos7840.c | 9 +---- drivers/usb/serial/navman.c | 7 +--- drivers/usb/serial/omninet.c | 11 ++---- drivers/usb/serial/opticon.c | 9 +---- drivers/usb/serial/oti6858.c | 7 +--- drivers/usb/serial/pl2303.c | 8 +--- drivers/usb/serial/quatech2.c | 19 +--------- drivers/usb/serial/safe_serial.c | 13 ++----- drivers/usb/serial/sierra.c | 17 +++------ drivers/usb/serial/spcp8x5.c | 18 ++++----- drivers/usb/serial/ssu100.c | 23 ++---------- drivers/usb/serial/symbolserial.c | 10 +---- drivers/usb/serial/ti_usb_3410_5052.c | 39 ++++++++----------- drivers/usb/serial/usb_wwan.c | 17 +++------ include/linux/tty.h | 1 - include/linux/tty_flip.h | 1 + net/bluetooth/rfcomm/tty.c | 16 +++----- net/irda/ircomm/ircomm_tty.c | 4 +- 146 files changed, 446 insertions(+), 988 deletions(-) diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c index a2a0c43..b403393 100644 --- a/drivers/staging/fwserial/fwserial.c +++ b/drivers/staging/fwserial/fwserial.c @@ -489,16 +489,11 @@ static void fwtty_do_hangup(struct work_struct *work) static void fwtty_emit_breaks(struct work_struct *work) { struct fwtty_port *port = to_port(to_delayed_work(work), emit_breaks); - struct tty_struct *tty; static const char buf[16]; unsigned long now = jiffies; unsigned long elapsed = now - port->break_last; int n, t, c, brk = 0; - tty = tty_port_tty_get(&port->port); - if (!tty) - return; - /* generate breaks at the line rate (but at least 1) */ n = (elapsed * port->cps) / HZ + 1; port->break_last = now; @@ -514,9 +509,7 @@ static void fwtty_emit_breaks(struct work_struct *work) if (c < t) break; } - tty_flip_buffer_push(tty); - - tty_kref_put(tty); + tty_flip_buffer_push(&port->port); if (port->mstatus & (UART_LSR_BI << 24)) schedule_delayed_work(&port->emit_breaks, FREQ_BREAKS); @@ -530,10 +523,6 @@ static void fwtty_pushrx(struct work_struct *work) struct buffered_rx *buf, *next; int n, c = 0; - tty = tty_port_tty_get(&port->port); - if (!tty) - return; - spin_lock_bh(&port->lock); list_for_each_entry_safe(buf, next, &port->buf_list, list) { n = tty_insert_flip_string_fixed_flag(&port->port, buf->data, @@ -545,7 +534,11 @@ static void fwtty_pushrx(struct work_struct *work) memmove(buf->data, buf->data + n, buf->n - n); buf->n -= n; } - __fwtty_throttle(port, tty); + tty = tty_port_tty_get(&port->port); + if (tty) { + __fwtty_throttle(port, tty); + tty_kref_put(tty); + } break; } else { list_del(&buf->list); @@ -553,13 +546,11 @@ static void fwtty_pushrx(struct work_struct *work) } } if (c > 0) - tty_flip_buffer_push(tty); + tty_flip_buffer_push(&port->port); if (list_empty(&port->buf_list)) clear_bit(BUFFERING_RX, &port->flags); spin_unlock_bh(&port->lock); - - tty_kref_put(tty); } static int fwtty_buffer_rx(struct fwtty_port *port, unsigned char *d, size_t n) @@ -594,10 +585,6 @@ static int fwtty_rx(struct fwtty_port *port, unsigned char *data, size_t len) unsigned lsr; int err = 0; - tty = tty_port_tty_get(&port->port); - if (!tty) - return -ENOENT; - fwtty_dbg(port, "%d", n); profile_size_distrib(port->stats.reads, n); @@ -634,16 +621,20 @@ static int fwtty_rx(struct fwtty_port *port, unsigned char *data, size_t len) c = tty_insert_flip_string_fixed_flag(&port->port, data, TTY_NORMAL, n); if (c > 0) - tty_flip_buffer_push(tty); + tty_flip_buffer_push(&port->port); n -= c; if (n) { /* start buffering and throttling */ n -= fwtty_buffer_rx(port, &data[c], n); - spin_lock_bh(&port->lock); - __fwtty_throttle(port, tty); - spin_unlock_bh(&port->lock); + tty = tty_port_tty_get(&port->port); + if (tty) { + spin_lock_bh(&port->lock); + __fwtty_throttle(port, tty); + spin_unlock_bh(&port->lock); + tty_kref_put(tty); + } } } else n -= fwtty_buffer_rx(port, data, n); @@ -654,8 +645,6 @@ static int fwtty_rx(struct fwtty_port *port, unsigned char *data, size_t len) } out: - tty_kref_put(tty); - port->icount.rx += len; port->stats.lost += n; return err;