Skip to content

Commit

Permalink
TTY: add tty_port_tty_wakeup helper
Browse files Browse the repository at this point in the history
It allows for cleaning up on a considerable amount of places. They did
port_get, wakeup, kref_put. Now the only thing needed is to call
tty_port_tty_wakeup which does exactly that.

One exception is ifx6x60 where tty_wakeup was open-coded. We now call
tty_wakeup properly there.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jiri Slaby authored and Greg Kroah-Hartman committed Mar 18, 2013
1 parent 6982a39 commit 6aad04f
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 176 deletions.
8 changes: 1 addition & 7 deletions arch/um/drivers/line.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ static irqreturn_t line_write_interrupt(int irq, void *data)
{
struct chan *chan = data;
struct line *line = chan->line;
struct tty_struct *tty;
int err;

/*
Expand All @@ -267,12 +266,7 @@ static irqreturn_t line_write_interrupt(int irq, void *data)
}
spin_unlock(&line->lock);

tty = tty_port_tty_get(&line->port);
if (tty == NULL)
return IRQ_NONE;

tty_wakeup(tty);
tty_kref_put(tty);
tty_port_tty_wakeup(&line->port);

return IRQ_HANDLED;
}
Expand Down
7 changes: 1 addition & 6 deletions drivers/isdn/capi/capi.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
{
struct capidev *cdev = ap->private;
#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
struct tty_struct *tty;
struct capiminor *mp;
u16 datahandle;
struct capincci *np;
Expand Down Expand Up @@ -627,11 +626,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
CAPIMSG_U16(skb->data, CAPIMSG_BASELEN + 4 + 2));
kfree_skb(skb);
capiminor_del_ack(mp, datahandle);
tty = tty_port_tty_get(&mp->port);
if (tty) {
tty_wakeup(tty);
tty_kref_put(tty);
}
tty_port_tty_wakeup(&mp->port);
handle_minor_send(mp);

} else {
Expand Down
6 changes: 1 addition & 5 deletions drivers/isdn/gigaset/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,8 @@ static const struct tty_operations if_ops = {
static void if_wake(unsigned long data)
{
struct cardstate *cs = (struct cardstate *)data;
struct tty_struct *tty = tty_port_tty_get(&cs->port);

if (tty) {
tty_wakeup(tty);
tty_kref_put(tty);
}
tty_port_tty_wakeup(&cs->port);
}

/*** interface to common ***/
Expand Down
13 changes: 2 additions & 11 deletions drivers/net/usb/hso.c
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,6 @@ static void hso_std_serial_write_bulk_callback(struct urb *urb)
{
struct hso_serial *serial = urb->context;
int status = urb->status;
struct tty_struct *tty;

/* sanity check */
if (!serial) {
Expand All @@ -1941,11 +1940,7 @@ static void hso_std_serial_write_bulk_callback(struct urb *urb)
return;
}
hso_put_activity(serial->parent);
tty = tty_port_tty_get(&serial->port);
if (tty) {
tty_wakeup(tty);
tty_kref_put(tty);
}
tty_port_tty_wakeup(&serial->port);
hso_kick_transmit(serial);

D1(" ");
Expand Down Expand Up @@ -2008,12 +2003,8 @@ static void ctrl_callback(struct urb *urb)
put_rxbuf_data_and_resubmit_ctrl_urb(serial);
spin_unlock(&serial->serial_lock);
} else {
struct tty_struct *tty = tty_port_tty_get(&serial->port);
hso_put_activity(serial->parent);
if (tty) {
tty_wakeup(tty);
tty_kref_put(tty);
}
tty_port_tty_wakeup(&serial->port);
/* response to a write command */
hso_kick_transmit(serial);
}
Expand Down
9 changes: 2 additions & 7 deletions drivers/s390/char/sclp_tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ sclp_tty_write_room (struct tty_struct *tty)
static void
sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc)
{
struct tty_struct *tty;
unsigned long flags;
void *page;

Expand All @@ -125,12 +124,8 @@ sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc)
struct sclp_buffer, list);
spin_unlock_irqrestore(&sclp_tty_lock, flags);
} while (buffer && sclp_emit_buffer(buffer, sclp_ttybuf_callback));
/* check if the tty needs a wake up call */
tty = tty_port_tty_get(&sclp_port);
if (tty != NULL) {
tty_wakeup(tty);
tty_kref_put(tty);
}

tty_port_tty_wakeup(&sclp_port);
}

static inline void
Expand Down
8 changes: 1 addition & 7 deletions drivers/s390/char/sclp_vt220.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ static struct sclp_register sclp_vt220_register = {
static void
sclp_vt220_process_queue(struct sclp_vt220_request *request)
{
struct tty_struct *tty;
unsigned long flags;
void *page;

Expand All @@ -139,12 +138,7 @@ sclp_vt220_process_queue(struct sclp_vt220_request *request)
} while (__sclp_vt220_emit(request));
if (request == NULL && sclp_vt220_flush_later)
sclp_vt220_emit_current();
/* Check if the tty needs a wake up call */
tty = tty_port_tty_get(&sclp_vt220_port);
if (tty) {
tty_wakeup(tty);
tty_kref_put(tty);
}
tty_port_tty_wakeup(&sclp_vt220_port);
}

#define SCLP_BUFFER_MAX_RETRY 1
Expand Down
10 changes: 2 additions & 8 deletions drivers/staging/fwserial/fwserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,6 @@ static void fwtty_tx_complete(struct fw_card *card, int rcode,
struct fwtty_transaction *txn)
{
struct fwtty_port *port = txn->port;
struct tty_struct *tty;
int len;

fwtty_dbg(port, "rcode: %d", rcode);
Expand All @@ -769,13 +768,8 @@ static void fwtty_tx_complete(struct fw_card *card, int rcode,
port->stats.dropped += txn->dma_pended.len;
}

if (len < WAKEUP_CHARS) {
tty = tty_port_tty_get(&port->port);
if (tty) {
tty_wakeup(tty);
tty_kref_put(tty);
}
}
if (len < WAKEUP_CHARS)
tty_port_tty_wakeup(&port->port);
}

static int fwtty_tx(struct fwtty_port *port, bool drain)
Expand Down
7 changes: 1 addition & 6 deletions drivers/staging/serqt_usb2/serqt_usb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ static void ProcessRxChar(struct usb_serial_port *port, unsigned char data)

static void qt_write_bulk_callback(struct urb *urb)
{
struct tty_struct *tty;
int status;
struct quatech_port *quatech_port;

Expand All @@ -278,11 +277,7 @@ static void qt_write_bulk_callback(struct urb *urb)

quatech_port = urb->context;

tty = tty_port_tty_get(&quatech_port->port->port);

if (tty)
tty_wakeup(tty);
tty_kref_put(tty);
tty_port_tty_wakeup(&quatech_port->port->port);
}

static void qt_interrupt_callback(struct urb *urb)
Expand Down
6 changes: 1 addition & 5 deletions drivers/tty/ehv_bytechan.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,9 @@ static void ehv_bc_tx_dequeue(struct ehv_bc_data *bc)
static irqreturn_t ehv_bc_tty_tx_isr(int irq, void *data)
{
struct ehv_bc_data *bc = data;
struct tty_struct *ttys = tty_port_tty_get(&bc->port);

ehv_bc_tx_dequeue(bc);
if (ttys) {
tty_wakeup(ttys);
tty_kref_put(ttys);
}
tty_port_tty_wakeup(&bc->port);

return IRQ_HANDLED;
}
Expand Down
7 changes: 1 addition & 6 deletions drivers/tty/hvc/hvsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,6 @@ static void hvsi_write_worker(struct work_struct *work)
{
struct hvsi_struct *hp =
container_of(work, struct hvsi_struct, writer.work);
struct tty_struct *tty;
unsigned long flags;
#ifdef DEBUG
static long start_j = 0;
Expand Down Expand Up @@ -895,11 +894,7 @@ static void hvsi_write_worker(struct work_struct *work)
start_j = 0;
#endif /* DEBUG */
wake_up_all(&hp->emptyq);
tty = tty_port_tty_get(&hp->port);
if (tty) {
tty_wakeup(tty);
tty_kref_put(tty);
}
tty_port_tty_wakeup(&hp->port);
}

out:
Expand Down
6 changes: 1 addition & 5 deletions drivers/tty/nozomi.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,15 +791,13 @@ static int send_data(enum port_type index, struct nozomi *dc)
const u8 toggle = port->toggle_ul;
void __iomem *addr = port->ul_addr[toggle];
const u32 ul_size = port->ul_size[toggle];
struct tty_struct *tty = tty_port_tty_get(&port->port);

/* Get data from tty and place in buf for now */
size = kfifo_out(&port->fifo_ul, dc->send_buf,
ul_size < SEND_BUF_MAX ? ul_size : SEND_BUF_MAX);

if (size == 0) {
DBG4("No more data to send, disable link:");
tty_kref_put(tty);
return 0;
}

Expand All @@ -809,10 +807,8 @@ static int send_data(enum port_type index, struct nozomi *dc)
write_mem32(addr, (u32 *) &size, 4);
write_mem32(addr + 4, (u32 *) dc->send_buf, size);

if (tty)
tty_wakeup(tty);
tty_port_tty_wakeup(&port->port);

tty_kref_put(tty);
return 1;
}

Expand Down
33 changes: 2 additions & 31 deletions drivers/tty/serial/ifx6x60.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,25 +442,6 @@ static void ifx_spi_setup_spi_header(unsigned char *txbuffer, int tx_count,
txbuffer[1] |= (more << IFX_SPI_MORE_BIT) & IFX_SPI_MORE_MASK;
}

/**
* ifx_spi_wakeup_serial - SPI space made
* @port_data: our SPI device
*
* We have emptied the FIFO enough that we want to get more data
* queued into it. Poke the line discipline via tty_wakeup so that
* it will feed us more bits
*/
static void ifx_spi_wakeup_serial(struct ifx_spi_device *ifx_dev)
{
struct tty_struct *tty;

tty = tty_port_tty_get(&ifx_dev->tty_port);
if (!tty)
return;
tty_wakeup(tty);
tty_kref_put(tty);
}

/**
* ifx_spi_prepare_tx_buffer - prepare transmit frame
* @ifx_dev: our SPI device
Expand Down Expand Up @@ -506,7 +487,7 @@ static int ifx_spi_prepare_tx_buffer(struct ifx_spi_device *ifx_dev)
tx_count += temp_count;
if (temp_count == queue_length)
/* poke port to get more data */
ifx_spi_wakeup_serial(ifx_dev);
tty_port_tty_wakeup(&ifx_dev->tty_port);
else /* more data in port, use next SPI message */
ifx_dev->spi_more = 1;
}
Expand Down Expand Up @@ -683,8 +664,6 @@ static void ifx_spi_insert_flip_string(struct ifx_spi_device *ifx_dev,
static void ifx_spi_complete(void *ctx)
{
struct ifx_spi_device *ifx_dev = ctx;
struct tty_struct *tty;
struct tty_ldisc *ldisc = NULL;
int length;
int actual_length;
unsigned char more;
Expand Down Expand Up @@ -762,15 +741,7 @@ static void ifx_spi_complete(void *ctx)
*/
ifx_spi_power_state_clear(ifx_dev,
IFX_SPI_POWER_DATA_PENDING);
tty = tty_port_tty_get(&ifx_dev->tty_port);
if (tty) {
ldisc = tty_ldisc_ref(tty);
if (ldisc) {
ldisc->ops->write_wakeup(tty);
tty_ldisc_deref(ldisc);
}
tty_kref_put(tty);
}
tty_port_tty_wakeup(&ifx_dev->tty_port);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions drivers/tty/tty_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ void tty_port_hangup(struct tty_port *port)
}
EXPORT_SYMBOL(tty_port_hangup);

/**
* tty_port_tty_wakeup - helper to wake up a tty
*
* @port: tty port
*/
void tty_port_tty_wakeup(struct tty_port *port)
{
struct tty_struct *tty = tty_port_tty_get(port);

if (tty) {
tty_wakeup(tty);
tty_kref_put(tty);
}
}
EXPORT_SYMBOL_GPL(tty_port_tty_wakeup);

/**
* tty_port_carrier_raised - carrier raised check
* @port: tty port
Expand Down
7 changes: 1 addition & 6 deletions drivers/usb/class/cdc-acm.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,10 @@ static void acm_write_bulk(struct urb *urb)
static void acm_softint(struct work_struct *work)
{
struct acm *acm = container_of(work, struct acm, work);
struct tty_struct *tty;

dev_vdbg(&acm->data->dev, "%s\n", __func__);

tty = tty_port_tty_get(&acm->port);
if (!tty)
return;
tty_wakeup(tty);
tty_kref_put(tty);
tty_port_tty_wakeup(&acm->port);
}

/*
Expand Down
17 changes: 3 additions & 14 deletions drivers/usb/serial/digi_acceleport.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ struct digi_port {

/* Local Function Declarations */

static void digi_wakeup_write(struct usb_serial_port *port);
static void digi_wakeup_write_lock(struct work_struct *work);
static int digi_write_oob_command(struct usb_serial_port *port,
unsigned char *buf, int count, int interruptible);
Expand Down Expand Up @@ -374,20 +373,10 @@ static void digi_wakeup_write_lock(struct work_struct *work)
unsigned long flags;

spin_lock_irqsave(&priv->dp_port_lock, flags);
digi_wakeup_write(port);
tty_port_tty_wakeup(&port->port);
spin_unlock_irqrestore(&priv->dp_port_lock, flags);
}

static void digi_wakeup_write(struct usb_serial_port *port)
{
struct tty_struct *tty = tty_port_tty_get(&port->port);
if (tty) {
tty_wakeup(tty);
tty_kref_put(tty);
}
}


/*
* Digi Write OOB Command
*
Expand Down Expand Up @@ -1044,7 +1033,7 @@ static void digi_write_bulk_callback(struct urb *urb)
}
}
/* wake up processes sleeping on writes immediately */
digi_wakeup_write(port);
tty_port_tty_wakeup(&port->port);
/* also queue up a wakeup at scheduler time, in case we */
/* lost the race in write_chan(). */
schedule_work(&priv->dp_wakeup_work);
Expand Down Expand Up @@ -1522,7 +1511,7 @@ static int digi_read_oob_callback(struct urb *urb)
/* port must be open to use tty struct */
if (rts) {
tty->hw_stopped = 0;
digi_wakeup_write(port);
tty_port_tty_wakeup(&port->port);
}
} else {
priv->dp_modem_signals &= ~TIOCM_CTS;
Expand Down
Loading

0 comments on commit 6aad04f

Please sign in to comment.