diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2025-12-06 18:38:19 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2025-12-06 18:38:19 -0800 |
| commit | edf602a17b03e6bca31c48f34ac8fc3341503ac1 (patch) | |
| tree | 9ceb349d8ac105570b6046f5628b32303728d32d /drivers/tty | |
| parent | 83bd89291f5cc866f60d32c34e268896c7ba8a3d (diff) | |
| parent | 75a9f4c54770f062f4b3813a83667452b326dda3 (diff) | |
| download | linux-edf602a17b03e6bca31c48f34ac8fc3341503ac1.tar.gz linux-edf602a17b03e6bca31c48f34ac8fc3341503ac1.tar.bz2 linux-edf602a17b03e6bca31c48f34ac8fc3341503ac1.zip | |
Merge tag 'tty-6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
Pull tty/serial updates from Greg KH:
"Here is the big set of tty/serial driver changes for 6.19-rc1. Nothing
major at all, just small constant churn to make the tty layer
"cleaner" as well as serial driver updates and even a new test added!
Included in here are:
- More tty/serial cleanups from Jiri
- tty tiocsti test added to hopefully ensure we don't regress in this
area again
- sc16is7xx driver updates
- imx serial driver updates
- 8250 driver updates
- new hardware device ids added
- other minor serial/tty driver cleanups and tweaks
All of these have been in linux-next for a while with no reported
issues"
* tag 'tty-6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (60 commits)
serial: sh-sci: Fix deadlock during RSCI FIFO overrun error
dt-bindings: serial: rsci: Drop "uart-has-rtscts: false"
LoongArch: dts: Add uart new compatible string
serial: 8250: Add Loongson uart driver support
dt-bindings: serial: 8250: Add Loongson uart compatible
serial: 8250: add driver for KEBA UART
serial: Keep rs485 settings for devices without firmware node
serial: qcom-geni: Enable Serial on SA8255p Qualcomm platforms
serial: qcom-geni: Enable PM runtime for serial driver
serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
tty: serial: samsung: Declare earlycon for Exynos850
serial: icom: Convert PCIBIOS_* return codes to errnos
serial: 8250-of: Fix style issues in 8250_of.c
serial: add support of CPCI cards
serial: mux: Fix kernel doc for mux_poll()
tty: replace use of system_unbound_wq with system_dfl_wq
serial: 8250_platform: simplify IRQF_SHARED handling
serial: 8250: make share_irqs local to 8250_platform
serial: 8250: move skip_txen_test to core
serial: drop SERIAL_8250_DEPRECATED_OPTIONS
...
Diffstat (limited to 'drivers/tty')
41 files changed, 1659 insertions, 1134 deletions
diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c index 329b30fac8fc..1bb2376af85c 100644 --- a/drivers/tty/moxa.c +++ b/drivers/tty/moxa.c @@ -487,25 +487,20 @@ static void moxa_wait_finish(void __iomem *ofsAddr) static void moxafunc(void __iomem *ofsAddr, u16 cmd, u16 arg) { - unsigned long flags; - spin_lock_irqsave(&moxafunc_lock, flags); + guard(spinlock_irqsave)(&moxafunc_lock); writew(arg, ofsAddr + FuncArg); writew(cmd, ofsAddr + FuncCode); moxa_wait_finish(ofsAddr); - spin_unlock_irqrestore(&moxafunc_lock, flags); } static int moxafuncret(void __iomem *ofsAddr, u16 cmd, u16 arg) { - unsigned long flags; - u16 ret; - spin_lock_irqsave(&moxafunc_lock, flags); + guard(spinlock_irqsave)(&moxafunc_lock); writew(arg, ofsAddr + FuncArg); writew(cmd, ofsAddr + FuncCode); moxa_wait_finish(ofsAddr); - ret = readw(ofsAddr + FuncArg); - spin_unlock_irqrestore(&moxafunc_lock, flags); - return ret; + + return readw(ofsAddr + FuncArg); } static void moxa_low_water_check(void __iomem *ofsAddr) @@ -1002,11 +997,11 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev) if (ret) goto err_free; - spin_lock_bh(&moxa_lock); - brd->ready = 1; - if (!timer_pending(&moxaTimer)) - mod_timer(&moxaTimer, jiffies + HZ / 50); - spin_unlock_bh(&moxa_lock); + scoped_guard(spinlock_bh, &moxa_lock) { + brd->ready = 1; + if (!timer_pending(&moxaTimer)) + mod_timer(&moxaTimer, jiffies + HZ / 50); + } first_idx = (brd - moxa_boards) * MAX_PORTS_PER_BOARD; for (i = 0; i < brd->numPorts; i++) @@ -1026,29 +1021,29 @@ static void moxa_board_deinit(struct moxa_board_conf *brd) { unsigned int a, opened, first_idx; - mutex_lock(&moxa_openlock); - spin_lock_bh(&moxa_lock); - brd->ready = 0; - spin_unlock_bh(&moxa_lock); - - /* pci hot-un-plug support */ - for (a = 0; a < brd->numPorts; a++) - if (tty_port_initialized(&brd->ports[a].port)) - 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); + scoped_guard(mutex, &moxa_openlock) { + scoped_guard(spinlock_bh, &moxa_lock) + brd->ready = 0; - while (1) { - opened = 0; + /* pci hot-un-plug support */ for (a = 0; a < brd->numPorts; a++) if (tty_port_initialized(&brd->ports[a].port)) - opened++; - mutex_unlock(&moxa_openlock); - if (!opened) - break; - msleep(50); - mutex_lock(&moxa_openlock); + 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++) + if (tty_port_initialized(&brd->ports[a].port)) + opened++; + if (!opened) + break; + mutex_unlock(&moxa_openlock); + msleep(50); + mutex_lock(&moxa_openlock); + } } first_idx = (brd - moxa_boards) * MAX_PORTS_PER_BOARD; @@ -1206,12 +1201,9 @@ static void moxa_shutdown(struct tty_port *port) static bool moxa_carrier_raised(struct tty_port *port) { struct moxa_port *ch = container_of(port, struct moxa_port, port); - int dcd; - spin_lock_irq(&port->lock); - dcd = ch->DCDState; - spin_unlock_irq(&port->lock); - return dcd; + guard(spinlock_irq)(&port->lock); + return ch->DCDState; } static void moxa_dtr_rts(struct tty_port *port, bool active) @@ -1225,37 +1217,31 @@ static int moxa_open(struct tty_struct *tty, struct file *filp) { struct moxa_board_conf *brd; struct moxa_port *ch; - int port; - - port = tty->index; - if (mutex_lock_interruptible(&moxa_openlock)) - return -ERESTARTSYS; - brd = &moxa_boards[port / MAX_PORTS_PER_BOARD]; - if (!brd->ready) { - mutex_unlock(&moxa_openlock); - return -ENODEV; - } + int port = tty->index; - if (port % MAX_PORTS_PER_BOARD >= brd->numPorts) { - mutex_unlock(&moxa_openlock); - return -ENODEV; - } - - ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; - ch->port.count++; - tty->driver_data = ch; - tty_port_tty_set(&ch->port, tty); - mutex_lock(&ch->port.mutex); - if (!tty_port_initialized(&ch->port)) { - ch->statusflags = 0; - moxa_set_tty_param(tty, &tty->termios); - MoxaPortLineCtrl(ch, true, true); - MoxaPortEnable(ch); - MoxaSetFifo(ch, ch->type == PORT_16550A); - tty_port_set_initialized(&ch->port, true); + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &moxa_openlock) { + brd = &moxa_boards[port / MAX_PORTS_PER_BOARD]; + if (!brd->ready) + return -ENODEV; + + if (port % MAX_PORTS_PER_BOARD >= brd->numPorts) + return -ENODEV; + + ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; + ch->port.count++; + tty->driver_data = ch; + tty_port_tty_set(&ch->port, tty); + + guard(mutex)(&ch->port.mutex); + if (!tty_port_initialized(&ch->port)) { + ch->statusflags = 0; + moxa_set_tty_param(tty, &tty->termios); + MoxaPortLineCtrl(ch, true, true); + MoxaPortEnable(ch); + MoxaSetFifo(ch, ch->type == PORT_16550A); + tty_port_set_initialized(&ch->port, true); + } } - mutex_unlock(&ch->port.mutex); - mutex_unlock(&moxa_openlock); return tty_port_block_til_ready(&ch->port, tty, filp); } @@ -1270,15 +1256,13 @@ static void moxa_close(struct tty_struct *tty, struct file *filp) static ssize_t moxa_write(struct tty_struct *tty, const u8 *buf, size_t count) { struct moxa_port *ch = tty->driver_data; - unsigned long flags; int len; if (ch == NULL) return 0; - spin_lock_irqsave(&moxa_lock, flags); - len = MoxaPortWriteData(tty, buf, count); - spin_unlock_irqrestore(&moxa_lock, flags); + scoped_guard(spinlock_irqsave, &moxa_lock) + len = MoxaPortWriteData(tty, buf, count); set_bit(LOWWAIT, &ch->statusflags); return len; @@ -1349,12 +1333,10 @@ static int moxa_tiocmset(struct tty_struct *tty, bool dtr_active, rts_active; struct moxa_port *ch; - mutex_lock(&moxa_openlock); + guard(mutex)(&moxa_openlock); ch = tty->driver_data; - if (!ch) { - mutex_unlock(&moxa_openlock); + if (!ch) return -EINVAL; - } MoxaPortGetLineOut(ch, &dtr_active, &rts_active); if (set & TIOCM_RTS) @@ -1366,7 +1348,7 @@ static int moxa_tiocmset(struct tty_struct *tty, if (clear & TIOCM_DTR) dtr_active = false; MoxaPortLineCtrl(ch, dtr_active, rts_active); - mutex_unlock(&moxa_openlock); + return 0; } @@ -1415,18 +1397,17 @@ static void moxa_hangup(struct tty_struct *tty) static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd) { - unsigned long flags; dcd = !!dcd; - spin_lock_irqsave(&p->port.lock, flags); - if (dcd != p->DCDState) { - p->DCDState = dcd; - spin_unlock_irqrestore(&p->port.lock, flags); - if (!dcd) - tty_port_tty_hangup(&p->port, true); + scoped_guard(spinlock_irqsave, &p->port.lock) { + if (dcd == p->DCDState) + return; + + p->DCDState = dcd; } - else - spin_unlock_irqrestore(&p->port.lock, flags); + + if (!dcd) + tty_port_tty_hangup(&p->port, true); } static int moxa_poll_port(struct moxa_port *p, unsigned int handle, @@ -1494,7 +1475,7 @@ static void moxa_poll(struct timer_list *unused) u16 __iomem *ip; unsigned int card, port, served = 0; - spin_lock(&moxa_lock); + guard(spinlock)(&moxa_lock); for (card = 0; card < MAX_BOARDS; card++) { brd = &moxa_boards[card]; if (!brd->ready) @@ -1525,7 +1506,6 @@ static void moxa_poll(struct timer_list *unused) if (served) mod_timer(&moxaTimer, jiffies + HZ / 50); - spin_unlock(&moxa_lock); } /******************************************************************************/ @@ -1861,13 +1841,11 @@ static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio, baud = MoxaPortSetBaud(port, baud); if (termio->c_iflag & (IXON | IXOFF | IXANY)) { - spin_lock_irq(&moxafunc_lock); + guard(spinlock_irq)(&moxafunc_lock); writeb(termio->c_cc[VSTART], ofsAddr + FuncArg); writeb(termio->c_cc[VSTOP], ofsAddr + FuncArg1); writeb(FC_SetXonXoff, ofsAddr + FuncCode); moxa_wait_finish(ofsAddr); - spin_unlock_irq(&moxafunc_lock); - } return baud; } @@ -2098,13 +2076,13 @@ static int moxa_get_serial_info(struct tty_struct *tty, if (!info) return -ENODEV; - mutex_lock(&info->port.mutex); + guard(mutex)(&info->port.mutex); ss->type = info->type; ss->line = info->port.tty->index; ss->flags = info->port.flags; ss->baud_base = 921600; ss->close_delay = jiffies_to_msecs(info->port.close_delay) / 10; - mutex_unlock(&info->port.mutex); + return 0; } @@ -2120,13 +2098,12 @@ static int moxa_set_serial_info(struct tty_struct *tty, close_delay = msecs_to_jiffies(ss->close_delay * 10); - mutex_lock(&info->port.mutex); + guard(mutex)(&info->port.mutex); if (!capable(CAP_SYS_ADMIN)) { if (close_delay != info->port.close_delay || ss->type != info->type || ((ss->flags & ~ASYNC_USR_MASK) != (info->port.flags & ~ASYNC_USR_MASK))) { - mutex_unlock(&info->port.mutex); return -EPERM; } } else { @@ -2136,7 +2113,7 @@ static int moxa_set_serial_info(struct tty_struct *tty, info->type = ss->type; } - mutex_unlock(&info->port.mutex); + return 0; } diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 553d8c70352b..214abeb89aaa 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -4165,7 +4165,7 @@ static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk) /** * gsm_modem_send_initial_msc - Send initial modem status message * - * @dlci channel + * @dlci: channel * * Send an initial MSC message after DLCI open to set the initial * modem status lines. This is only done for basic mode. diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index 4a4dc58b866a..3c9dcb0928c6 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -263,21 +263,18 @@ static int n_hdlc_tty_open(struct tty_struct *tty) */ static void n_hdlc_send_frames(struct n_hdlc *n_hdlc, struct tty_struct *tty) { - unsigned long flags; struct n_hdlc_buf *tbuf; ssize_t actual; check_again: - - spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); - if (n_hdlc->tbusy) { - n_hdlc->woke_up = true; - spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); - return; + scoped_guard(spinlock_irqsave, &n_hdlc->tx_buf_list.spinlock) { + if (n_hdlc->tbusy) { + n_hdlc->woke_up = true; + return; + } + n_hdlc->tbusy = true; + n_hdlc->woke_up = false; } - n_hdlc->tbusy = true; - n_hdlc->woke_up = false; - spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list); while (tbuf) { @@ -324,9 +321,8 @@ check_again: clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); /* Clear the re-entry flag */ - spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); - n_hdlc->tbusy = false; - spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); + scoped_guard(spinlock_irqsave, &n_hdlc->tx_buf_list.spinlock) + n_hdlc->tbusy = false; if (n_hdlc->woke_up) goto check_again; @@ -584,9 +580,7 @@ static int n_hdlc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) { struct n_hdlc *n_hdlc = tty->disc_data; - int error = 0; int count; - unsigned long flags; struct n_hdlc_buf *buf = NULL; pr_debug("%s() called %d\n", __func__, cmd); @@ -595,29 +589,27 @@ static int n_hdlc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, case FIONREAD: /* report count of read data available */ /* in next available frame (if any) */ - spin_lock_irqsave(&n_hdlc->rx_buf_list.spinlock, flags); - buf = list_first_entry_or_null(&n_hdlc->rx_buf_list.list, - struct n_hdlc_buf, list_item); - if (buf) - count = buf->count; - else - count = 0; - spin_unlock_irqrestore(&n_hdlc->rx_buf_list.spinlock, flags); - error = put_user(count, (int __user *)arg); - break; + scoped_guard(spinlock_irqsave, &n_hdlc->rx_buf_list.spinlock) { + buf = list_first_entry_or_null(&n_hdlc->rx_buf_list.list, + struct n_hdlc_buf, list_item); + if (buf) + count = buf->count; + else + count = 0; + } + return put_user(count, (int __user *)arg); case TIOCOUTQ: /* get the pending tx byte count in the driver */ count = tty_chars_in_buffer(tty); /* add size of next output frame in queue */ - spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); - buf = list_first_entry_or_null(&n_hdlc->tx_buf_list.list, - struct n_hdlc_buf, list_item); - if (buf) - count += buf->count; - spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); - error = put_user(count, (int __user *)arg); - break; + scoped_guard(spinlock_irqsave, &n_hdlc->tx_buf_list.spinlock) { + buf = list_first_entry_or_null(&n_hdlc->tx_buf_list.list, + struct n_hdlc_buf, list_item); + if (buf) + count += buf->count; + } + return put_user(count, (int __user *)arg); case TCFLSH: switch (arg) { @@ -628,11 +620,8 @@ static int n_hdlc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, fallthrough; /* to default */ default: - error = n_tty_ioctl_helper(tty, cmd, arg); - break; + return n_tty_ioctl_helper(tty, cmd, arg); } - return error; - } /* end of n_hdlc_tty_ioctl() */ /** @@ -726,14 +715,10 @@ static struct n_hdlc *n_hdlc_alloc(void) static void n_hdlc_buf_return(struct n_hdlc_buf_list *buf_list, struct n_hdlc_buf *buf) { - unsigned long flags; - - spin_lock_irqsave(&buf_list->spinlock, flags); + guard(spinlock_irqsave)(&buf_list->spinlock); list_add(&buf->list_item, &buf_list->list); buf_list->count++; - - spin_unlock_irqrestore(&buf_list->spinlock, flags); } /** @@ -744,14 +729,10 @@ static void n_hdlc_buf_return(struct n_hdlc_buf_list *buf_list, static void n_hdlc_buf_put(struct n_hdlc_buf_list *buf_list, struct n_hdlc_buf *buf) { - unsigned long flags; - - spin_lock_irqsave(&buf_list->spinlock, flags); + guard(spinlock_irqsave)(&buf_list->spinlock); list_add_tail(&buf->list_item, &buf_list->list); buf_list->count++; - - spin_unlock_irqrestore(&buf_list->spinlock, flags); } /* end of n_hdlc_buf_put() */ /** @@ -764,10 +745,9 @@ static void n_hdlc_buf_put(struct n_hdlc_buf_list *buf_list, */ static struct n_hdlc_buf *n_hdlc_buf_get(struct n_hdlc_buf_list *buf_list) { - unsigned long flags; struct n_hdlc_buf *buf; - spin_lock_irqsave(&buf_list->spinlock, flags); + guard(spinlock_irqsave)(&buf_list->spinlock); buf = list_first_entry_or_null(&buf_list->list, struct n_hdlc_buf, list_item); @@ -776,7 +756,6 @@ static struct n_hdlc_buf *n_hdlc_buf_get(struct n_hdlc_buf_list *buf_list) buf_list->count--; } - spin_unlock_irqrestore(&buf_list->spinlock, flags); return buf; } /* end of n_hdlc_buf_get() */ diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c index 6af3f3a0b531..e6a0f5b40d0a 100644 --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -324,12 +324,9 @@ static void reset_buffer_flags(struct n_tty_data *ldata) static void n_tty_packet_mode_flush(struct tty_struct *tty) { - unsigned long flags; - if (tty->link->ctrl.packet) { - spin_lock_irqsave(&tty->ctrl.lock, flags); - tty->ctrl.pktstatus |= TIOCPKT_FLUSHREAD; - spin_unlock_irqrestore(&tty->ctrl.lock, flags); + scoped_guard(spinlock_irqsave, &tty->ctrl.lock) + tty->ctrl.pktstatus |= TIOCPKT_FLUSHREAD; wake_up_interruptible(&tty->link->read_wait); } } @@ -349,13 +346,12 @@ static void n_tty_packet_mode_flush(struct tty_struct *tty) */ static void n_tty_flush_buffer(struct tty_struct *tty) { - down_write(&tty->termios_rwsem); + guard(rwsem_write)(&tty->termios_rwsem); reset_buffer_flags(tty->disc_data); n_tty_kick_worker(tty); if (tty->link) n_tty_packet_mode_flush(tty); - up_write(&tty->termios_rwsem); } /** @@ -737,24 +733,22 @@ static void commit_echoes(struct tty_struct *tty) size_t nr, old, echoed; size_t head; - mutex_lock(&ldata->output_lock); - head = ldata->echo_head; - ldata->echo_mark = head; - old = ldata->echo_commit - ldata->echo_tail; - - /* Process committed echoes if the accumulated # of bytes - * is over the threshold (and try again each time another - * block is accumulated) */ - nr = head - ldata->echo_tail; - if (nr < ECHO_COMMIT_WATERMARK || - (nr % ECHO_BLOCK > old % ECHO_BLOCK)) { - mutex_unlock(&ldata->output_lock); - return; - } + scoped_guard(mutex, &ldata->output_lock) { + head = ldata->echo_head; + ldata->echo_mark = head; + old = ldata->echo_commit - ldata->echo_tail; + + /* + * Process committed echoes if the accumulated # of bytes is over the threshold + * (and try again each time another block is accumulated) + */ + nr = head - ldata->echo_tail; + if (nr < ECHO_COMMIT_WATERMARK || (nr % ECHO_BLOCK > old % ECHO_BLOCK)) + return; - ldata->echo_commit = head; - echoed = __process_echoes(tty); - mutex_unlock(&ldata->output_lock); + ldata->echo_commit = head; + echoed = __process_echoes(tty); + } if (echoed && tty->ops->flush_chars) tty->ops->flush_chars(tty); @@ -768,10 +762,10 @@ static void process_echoes(struct tty_struct *tty) if (ldata->echo_mark == ldata->echo_tail) return; - mutex_lock(&ldata->output_lock); - ldata->echo_commit = ldata->echo_mark; - echoed = __process_echoes(tty); - mutex_unlock(&ldata->output_lock); + scoped_guard(mutex, &ldata->output_lock) { + ldata->echo_commit = ldata->echo_mark; + echoed = __process_echoes(tty); + } if (echoed && tty->ops->flush_chars) tty->ops->flush_chars(tty); @@ -786,10 +780,9 @@ static void flush_echoes(struct tty_struct *tty) ldata->echo_commit == ldata->echo_head) return; - mutex_lock(&ldata->output_lock); + guard(mutex)(&ldata->output_lock); ldata->echo_commit = ldata->echo_head; __process_echoes(tty); - mutex_unlock(&ldata->output_lock); } /** @@ -1078,18 +1071,19 @@ static void isig(int sig, struct tty_struct *tty) if (L_NOFLSH(tty)) { /* signal only */ __isig(sig, tty); + return; + } - } else { /* signal and flush */ - up_read(&tty->termios_rwsem); - down_write(&tty->termios_rwsem); - + /* signal and flush */ + up_read(&tty->termios_rwsem); + scoped_guard(rwsem_write, &tty->termios_rwsem) { __isig(sig, tty); /* clear echo buffer */ - mutex_lock(&ldata->output_lock); - ldata->echo_head = ldata->echo_tail = 0; - ldata->echo_mark = ldata->echo_commit = 0; - mutex_unlock(&ldata->output_lock); + scoped_guard(mutex, &ldata->output_lock) { + ldata->echo_head = ldata->echo_tail = 0; + ldata->echo_mark = ldata->echo_commit = 0; + } /* clear output buffer */ tty_driver_flush_buffer(tty); @@ -1100,10 +1094,8 @@ static void isig(int sig, struct tty_struct *tty) /* notify pty master of flush */ if (tty->link) n_tty_packet_mode_flush(tty); - - up_write(&tty->termios_rwsem); - down_read(&tty->termios_rwsem); } + down_read(&tty->termios_rwsem); } /** @@ -1683,7 +1675,7 @@ n_tty_receive_buf_common(struct tty_struct *tty, const u8 *cp, const u8 *fp, size_t n, rcvd = 0; int room, overflow; - down_read(&tty->termios_rwsem); + guard(rwsem_read)(&tty->termios_rwsem); do { /* @@ -1752,8 +1744,6 @@ n_tty_receive_buf_common(struct tty_struct *tty, const u8 *cp, const u8 *fp, n_tty_kick_worker(tty); } - up_read(&tty->termios_rwsem); - return rcvd; } @@ -1879,10 +1869,9 @@ static void n_tty_close(struct tty_struct *tty) if (tty->link) n_tty_packet_mode_flush(tty); - down_write(&tty->termios_rwsem); + guard(rwsem_write)(&tty->termios_rwsem); vfree(ldata); tty->disc_data = NULL; - up_write(&tty->termios_rwsem); } /** @@ -2247,10 +2236,10 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf, u8 cs; if (kb != kbuf) break; - spin_lock_irq(&tty->link->ctrl.lock); - cs = tty->link->ctrl.pktstatus; - tty->link->ctrl.pktstatus = 0; - spin_unlock_irq(&tty->link->ctrl.lock); + scoped_guard(spinlock_irq, &tty->link->ctrl.lock) { + cs = tty->link->ctrl.pktstatus; + tty->link->ctrl.pktstatus = 0; + } *kb++ = cs; nr--; break; @@ -2357,7 +2346,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, return retval; } |
