Skip to content

Commit aa27a09

Browse files
Jiri Slabygregkh
authored andcommitted
TTY: add tty_port_tty_hangup helper
It allows for cleaning up on a considerable amount of places. They did port_get, hangup, kref_put. Now the only thing needed is to call tty_port_tty_hangup which does exactly that. And they can also decide whether to consider CLOCAL or completely ignore that. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e4408ce commit aa27a09

16 files changed

Lines changed: 58 additions & 148 deletions

File tree

‎arch/um/drivers/chan_kern.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,7 @@ void chan_interrupt(struct line *line, int irq)
568568
reactivate_fd(chan->fd, irq);
569569
if (err == -EIO) {
570570
if (chan->primary) {
571-
struct tty_struct *tty = tty_port_tty_get(&line->port);
572-
if (tty != NULL) {
573-
tty_hangup(tty);
574-
tty_kref_put(tty);
575-
}
571+
tty_port_tty_hangup(&line->port, false);
576572
if (line->chan_out != chan)
577573
close_one_chan(line->chan_out, 1);
578574
}

‎drivers/mmc/card/sdio_uart.c‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ static void sdio_uart_port_put(struct sdio_uart_port *port)
134134
static void sdio_uart_port_remove(struct sdio_uart_port *port)
135135
{
136136
struct sdio_func *func;
137-
struct tty_struct *tty;
138137

139138
BUG_ON(sdio_uart_table[port->index] != port);
140139

@@ -155,12 +154,8 @@ static void sdio_uart_port_remove(struct sdio_uart_port *port)
155154
sdio_claim_host(func);
156155
port->func = NULL;
157156
mutex_unlock(&port->func_lock);
158-
tty = tty_port_tty_get(&port->port);
159157
/* tty_hangup is async so is this safe as is ?? */
160-
if (tty) {
161-
tty_hangup(tty);
162-
tty_kref_put(tty);
163-
}
158+
tty_port_tty_hangup(&port->port, false);
164159
mutex_unlock(&port->port.mutex);
165160
sdio_release_irq(func);
166161
sdio_disable_func(func);
@@ -492,11 +487,7 @@ static void sdio_uart_check_modem_status(struct sdio_uart_port *port)
492487
wake_up_interruptible(&port->port.open_wait);
493488
else {
494489
/* DCD drop - hang up if tty attached */
495-
tty = tty_port_tty_get(&port->port);
496-
if (tty) {
497-
tty_hangup(tty);
498-
tty_kref_put(tty);
499-
}
490+
tty_port_tty_hangup(&port->port, false);
500491
}
501492
}
502493
if (status & UART_MSR_DCTS) {

‎drivers/net/usb/hso.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,18 +3124,13 @@ static void hso_serial_ref_free(struct kref *ref)
31243124
static void hso_free_interface(struct usb_interface *interface)
31253125
{
31263126
struct hso_serial *hso_dev;
3127-
struct tty_struct *tty;
31283127
int i;
31293128

31303129
for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
31313130
if (serial_table[i] &&
31323131
(serial_table[i]->interface == interface)) {
31333132
hso_dev = dev2ser(serial_table[i]);
3134-
tty = tty_port_tty_get(&hso_dev->port);
3135-
if (tty) {
3136-
tty_hangup(tty);
3137-
tty_kref_put(tty);
3138-
}
3133+
tty_port_tty_hangup(&hso_dev->port, false);
31393134
mutex_lock(&hso_dev->parent->mutex);
31403135
hso_dev->parent->usb_gone = 1;
31413136
mutex_unlock(&hso_dev->parent->mutex);

‎drivers/tty/cyclades.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,14 +1124,8 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
11241124
readl(&info->u.cyz.ch_ctrl->rs_status);
11251125
if (dcd & C_RS_DCD)
11261126
wake_up_interruptible(&info->port.open_wait);
1127-
else {
1128-
struct tty_struct *tty;
1129-
tty = tty_port_tty_get(&info->port);
1130-
if (tty) {
1131-
tty_hangup(tty);
1132-
tty_kref_put(tty);
1133-
}
1134-
}
1127+
else
1128+
tty_port_tty_hangup(&info->port, false);
11351129
}
11361130
break;
11371131
case C_CM_MCTS:

‎drivers/tty/moxa.c‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -913,16 +913,12 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)
913913

914914
/* pci hot-un-plug support */
915915
for (a = 0; a < brd->numPorts; a++)
916-
if (brd->ports[a].port.flags & ASYNC_INITIALIZED) {
917-
struct tty_struct *tty = tty_port_tty_get(
918-
&brd->ports[a].port);
919-
if (tty) {
920-
tty_hangup(tty);
921-
tty_kref_put(tty);
922-
}
923-
}
916+
if (brd->ports[a].port.flags & ASYNC_INITIALIZED)
917+
tty_port_tty_hangup(&brd->ports[a].port, false);
918+
924919
for (a = 0; a < MAX_PORTS_PER_BOARD; a++)
925920
tty_port_destroy(&brd->ports[a].port);
921+
926922
while (1) {
927923
opened = 0;
928924
for (a = 0; a < brd->numPorts; a++)
@@ -1365,18 +1361,15 @@ static void moxa_hangup(struct tty_struct *tty)
13651361

13661362
static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
13671363
{
1368-
struct tty_struct *tty;
13691364
unsigned long flags;
13701365
dcd = !!dcd;
13711366

13721367
spin_lock_irqsave(&p->port.lock, flags);
13731368
if (dcd != p->DCDState) {
13741369
p->DCDState = dcd;
13751370
spin_unlock_irqrestore(&p->port.lock, flags);
1376-
tty = tty_port_tty_get(&p->port);
1377-
if (tty && !C_CLOCAL(tty) && !dcd)
1378-
tty_hangup(tty);
1379-
tty_kref_put(tty);
1371+
if (!dcd)
1372+
tty_port_tty_hangup(&p->port, true);
13801373
}
13811374
else
13821375
spin_unlock_irqrestore(&p->port.lock, flags);

‎drivers/tty/n_gsm.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,11 +1418,7 @@ static void gsm_dlci_close(struct gsm_dlci *dlci)
14181418
pr_debug("DLCI %d goes closed.\n", dlci->addr);
14191419
dlci->state = DLCI_CLOSED;
14201420
if (dlci->addr != 0) {
1421-
struct tty_struct *tty = tty_port_tty_get(&dlci->port);
1422-
if (tty) {
1423-
tty_hangup(tty);
1424-
tty_kref_put(tty);
1425-
}
1421+
tty_port_tty_hangup(&dlci->port, false);
14261422
kfifo_reset(dlci->fifo);
14271423
} else
14281424
dlci->gsm->dead = 1;

‎drivers/tty/nozomi.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,12 +1501,9 @@ static void tty_exit(struct nozomi *dc)
15011501

15021502
DBG1(" ");
15031503

1504-
for (i = 0; i < MAX_PORT; ++i) {
1505-
struct tty_struct *tty = tty_port_tty_get(&dc->port[i].port);
1506-
if (tty && list_empty(&tty->hangup_work.entry))
1507-
tty_hangup(tty);
1508-
tty_kref_put(tty);
1509-
}
1504+
for (i = 0; i < MAX_PORT; ++i)
1505+
tty_port_tty_hangup(&dc->port[i].port, false);
1506+
15101507
/* Racy below - surely should wait for scheduled work to be done or
15111508
complete off a hangup method ? */
15121509
while (dc->open_ttys)

‎drivers/tty/rocket.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,15 +521,10 @@ static void rp_handle_port(struct r_port *info)
521521
(ChanStatus & CD_ACT) ? "on" : "off");
522522
#endif
523523
if (!(ChanStatus & CD_ACT) && info->cd_status) {
524-
struct tty_struct *tty;
525524
#ifdef ROCKET_DEBUG_HANGUP
526525
printk(KERN_INFO "CD drop, calling hangup.\n");
527526
#endif
528-
tty = tty_port_tty_get(&info->port);
529-
if (tty) {
530-
tty_hangup(tty);
531-
tty_kref_put(tty);
532-
}
527+
tty_port_tty_hangup(&info->port, false);
533528
}
534529
info->cd_status = (ChanStatus & CD_ACT) ? 1 : 0;
535530
wake_up_interruptible(&info->port.open_wait);

‎drivers/tty/serial/ifx6x60.c‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -269,23 +269,6 @@ static void mrdy_assert(struct ifx_spi_device *ifx_dev)
269269
mrdy_set_high(ifx_dev);
270270
}
271271

272-
/**
273-
* ifx_spi_hangup - hang up an IFX device
274-
* @ifx_dev: our SPI device
275-
*
276-
* Hang up the tty attached to the IFX device if one is currently
277-
* open. If not take no action
278-
*/
279-
static void ifx_spi_ttyhangup(struct ifx_spi_device *ifx_dev)
280-
{
281-
struct tty_port *pport = &ifx_dev->tty_port;
282-
struct tty_struct *tty = tty_port_tty_get(pport);
283-
if (tty) {
284-
tty_hangup(tty);
285-
tty_kref_put(tty);
286-
}
287-
}
288-
289272
/**
290273
* ifx_spi_timeout - SPI timeout
291274
* @arg: our SPI device
@@ -298,7 +281,7 @@ static void ifx_spi_timeout(unsigned long arg)
298281
struct ifx_spi_device *ifx_dev = (struct ifx_spi_device *)arg;
299282

300283
dev_warn(&ifx_dev->spi_dev->dev, "*** SPI Timeout ***");
301-
ifx_spi_ttyhangup(ifx_dev);
284+
tty_port_tty_hangup(&ifx_dev->tty_port, false);
302285
mrdy_set_low(ifx_dev);
303286
clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags);
304287
}
@@ -933,7 +916,7 @@ static irqreturn_t ifx_spi_reset_interrupt(int irq, void *dev)
933916
set_bit(MR_INPROGRESS, &ifx_dev->mdm_reset_state);
934917
if (!solreset) {
935918
/* unsolicited reset */
936-
ifx_spi_ttyhangup(ifx_dev);
919+
tty_port_tty_hangup(&ifx_dev->tty_port, false);
937920
}
938921
} else {
939922
/* exited reset */

‎drivers/tty/tty_port.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,23 @@ void tty_port_hangup(struct tty_port *port)
232232
}
233233
EXPORT_SYMBOL(tty_port_hangup);
234234

235+
/**
236+
* tty_port_tty_hangup - helper to hang up a tty
237+
*
238+
* @port: tty port
239+
* @check_clocal: hang only ttys with CLOCAL unset?
240+
*/
241+
void tty_port_tty_hangup(struct tty_port *port, bool check_clocal)
242+
{
243+
struct tty_struct *tty = tty_port_tty_get(port);
244+
245+
if (tty && (!check_clocal || !C_CLOCAL(tty))) {
246+
tty_hangup(tty);
247+
tty_kref_put(tty);
248+
}
249+
}
250+
EXPORT_SYMBOL_GPL(tty_port_tty_hangup);
251+
235252
/**
236253
* tty_port_tty_wakeup - helper to wake up a tty
237254
*

0 commit comments

Comments
 (0)