Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa27a094 authored by Jiri Slaby's avatar Jiri Slaby Committed by Greg Kroah-Hartman
Browse files

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: default avatarJiri Slaby <jslaby@suse.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e4408ce3
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -568,11 +568,7 @@ void chan_interrupt(struct line *line, int irq)
		reactivate_fd(chan->fd, irq);
	if (err == -EIO) {
		if (chan->primary) {
			struct tty_struct *tty = tty_port_tty_get(&line->port);
			if (tty != NULL) {
				tty_hangup(tty);
				tty_kref_put(tty);
			}
			tty_port_tty_hangup(&line->port, false);
			if (line->chan_out != chan)
				close_one_chan(line->chan_out, 1);
		}
+2 −11
Original line number Diff line number Diff line
@@ -134,7 +134,6 @@ static void sdio_uart_port_put(struct sdio_uart_port *port)
static void sdio_uart_port_remove(struct sdio_uart_port *port)
{
	struct sdio_func *func;
	struct tty_struct *tty;

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

@@ -155,12 +154,8 @@ static void sdio_uart_port_remove(struct sdio_uart_port *port)
	sdio_claim_host(func);
	port->func = NULL;
	mutex_unlock(&port->func_lock);
	tty = tty_port_tty_get(&port->port);
	/* tty_hangup is async so is this safe as is ?? */
	if (tty) {
		tty_hangup(tty);
		tty_kref_put(tty);
	}
	tty_port_tty_hangup(&port->port, false);
	mutex_unlock(&port->port.mutex);
	sdio_release_irq(func);
	sdio_disable_func(func);
@@ -492,11 +487,7 @@ static void sdio_uart_check_modem_status(struct sdio_uart_port *port)
			wake_up_interruptible(&port->port.open_wait);
		else {
			/* DCD drop - hang up if tty attached */
			tty = tty_port_tty_get(&port->port);
			if (tty) {
				tty_hangup(tty);
				tty_kref_put(tty);
			}
			tty_port_tty_hangup(&port->port, false);
		}
	}
	if (status & UART_MSR_DCTS) {
+1 −6
Original line number Diff line number Diff line
@@ -3124,18 +3124,13 @@ static void hso_serial_ref_free(struct kref *ref)
static void hso_free_interface(struct usb_interface *interface)
{
	struct hso_serial *hso_dev;
	struct tty_struct *tty;
	int i;

	for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
		if (serial_table[i] &&
		    (serial_table[i]->interface == interface)) {
			hso_dev = dev2ser(serial_table[i]);
			tty = tty_port_tty_get(&hso_dev->port);
			if (tty) {
				tty_hangup(tty);
				tty_kref_put(tty);
			}
			tty_port_tty_hangup(&hso_dev->port, false);
			mutex_lock(&hso_dev->parent->mutex);
			hso_dev->parent->usb_gone = 1;
			mutex_unlock(&hso_dev->parent->mutex);
+2 −8
Original line number Diff line number Diff line
@@ -1124,14 +1124,8 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
					readl(&info->u.cyz.ch_ctrl->rs_status);
				if (dcd & C_RS_DCD)
					wake_up_interruptible(&info->port.open_wait);
				else {
					struct tty_struct *tty;
					tty = tty_port_tty_get(&info->port);
					if (tty) {
						tty_hangup(tty);
						tty_kref_put(tty);
					}
				}
				else
					tty_port_tty_hangup(&info->port, false);
			}
			break;
		case C_CM_MCTS:
+6 −13
Original line number Diff line number Diff line
@@ -913,16 +913,12 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)

	/* pci hot-un-plug support */
	for (a = 0; a < brd->numPorts; a++)
		if (brd->ports[a].port.flags & ASYNC_INITIALIZED) {
			struct tty_struct *tty = tty_port_tty_get(
						&brd->ports[a].port);
			if (tty) {
				tty_hangup(tty);
				tty_kref_put(tty);
			}
		}
		if (brd->ports[a].port.flags & ASYNC_INITIALIZED)
			tty_port_tty_hangup(&brd->ports[a].port, false);

	for (a = 0; a < MAX_PORTS_PER_BOARD; a++)
		tty_port_destroy(&brd->ports[a].port);

	while (1) {
		opened = 0;
		for (a = 0; a < brd->numPorts; a++)
@@ -1365,7 +1361,6 @@ static void moxa_hangup(struct tty_struct *tty)

static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
{
	struct tty_struct *tty;
	unsigned long flags;
	dcd = !!dcd;

@@ -1373,10 +1368,8 @@ static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
	if (dcd != p->DCDState) {
        	p->DCDState = dcd;
        	spin_unlock_irqrestore(&p->port.lock, flags);
		tty = tty_port_tty_get(&p->port);
		if (tty && !C_CLOCAL(tty) && !dcd)
			tty_hangup(tty);
		tty_kref_put(tty);
		if (!dcd)
			tty_port_tty_hangup(&p->port, true);
	}
	else
		spin_unlock_irqrestore(&p->port.lock, flags);
Loading