Merge tag 'tty-4.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty

Pull tty/serial fixes from Greg KH:
"Here's some TTY and serial driver fixes for reported issues.

All of these have been in linux-next successfully"

* tag 'tty-4.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty:
pty: Fix input race when closing
tty/n_gsm.c: fix a memory leak when gsmtty is removed
Revert "serial/amba-pl011: Leave the TX IRQ alone when the UART is not open"
serial: omap: Fix error handling in probe
earlycon: Revert log warnings

Changed files
+64 -34
Documentation
serial
drivers
include
linux
+3
Documentation/serial/tty.txt
··· 198 198 199 199 TTY_OTHER_CLOSED Device is a pty and the other side has closed. 200 200 201 + TTY_OTHER_DONE Device is a pty and the other side has closed and 202 + all pending input processing has been completed. 203 + 201 204 TTY_NO_WRITE_SPLIT Prevent driver from splitting up writes into 202 205 smaller chunks. 203 206
+2 -3
drivers/tty/n_gsm.c
··· 3170 3170 return gsmtty_modem_update(dlci, encode); 3171 3171 } 3172 3172 3173 - static void gsmtty_remove(struct tty_driver *driver, struct tty_struct *tty) 3173 + static void gsmtty_cleanup(struct tty_struct *tty) 3174 3174 { 3175 3175 struct gsm_dlci *dlci = tty->driver_data; 3176 3176 struct gsm_mux *gsm = dlci->gsm; ··· 3178 3178 dlci_put(dlci); 3179 3179 dlci_put(gsm->dlci[0]); 3180 3180 mux_put(gsm); 3181 - driver->ttys[tty->index] = NULL; 3182 3181 } 3183 3182 3184 3183 /* Virtual ttys for the demux */ ··· 3198 3199 .tiocmget = gsmtty_tiocmget, 3199 3200 .tiocmset = gsmtty_tiocmset, 3200 3201 .break_ctl = gsmtty_break_ctl, 3201 - .remove = gsmtty_remove, 3202 + .cleanup = gsmtty_cleanup, 3202 3203 }; 3203 3204 3204 3205
+2 -2
drivers/tty/n_hdlc.c
··· 600 600 add_wait_queue(&tty->read_wait, &wait); 601 601 602 602 for (;;) { 603 - if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { 603 + if (test_bit(TTY_OTHER_DONE, &tty->flags)) { 604 604 ret = -EIO; 605 605 break; 606 606 } ··· 828 828 /* set bits for operations that won't block */ 829 829 if (n_hdlc->rx_buf_list.head) 830 830 mask |= POLLIN | POLLRDNORM; /* readable */ 831 - if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) 831 + if (test_bit(TTY_OTHER_DONE, &tty->flags)) 832 832 mask |= POLLHUP; 833 833 if (tty_hung_up_p(filp)) 834 834 mask |= POLLHUP;
+18 -4
drivers/tty/n_tty.c
··· 1949 1949 return ldata->commit_head - ldata->read_tail >= amt; 1950 1950 } 1951 1951 1952 + static inline int check_other_done(struct tty_struct *tty) 1953 + { 1954 + int done = test_bit(TTY_OTHER_DONE, &tty->flags); 1955 + if (done) { 1956 + /* paired with cmpxchg() in check_other_closed(); ensures 1957 + * read buffer head index is not stale 1958 + */ 1959 + smp_mb__after_atomic(); 1960 + } 1961 + return done; 1962 + } 1963 + 1952 1964 /** 1953 1965 * copy_from_read_buf - copy read data directly 1954 1966 * @tty: terminal device ··· 2179 2167 struct n_tty_data *ldata = tty->disc_data; 2180 2168 unsigned char __user *b = buf; 2181 2169 DEFINE_WAIT_FUNC(wait, woken_wake_function); 2182 - int c; 2170 + int c, done; 2183 2171 int minimum, time; 2184 2172 ssize_t retval = 0; 2185 2173 long timeout; ··· 2247 2235 ((minimum - (b - buf)) >= 1)) 2248 2236 ldata->minimum_to_wake = (minimum - (b - buf)); 2249 2237 2238 + done = check_other_done(tty); 2239 + 2250 2240 if (!input_available_p(tty, 0)) { 2251 - if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { 2241 + if (done) { 2252 2242 retval = -EIO; 2253 2243 break; 2254 2244 } ··· 2457 2443 2458 2444 poll_wait(file, &tty->read_wait, wait); 2459 2445 poll_wait(file, &tty->write_wait, wait); 2446 + if (check_other_done(tty)) 2447 + mask |= POLLHUP; 2460 2448 if (input_available_p(tty, 1)) 2461 2449 mask |= POLLIN | POLLRDNORM; 2462 2450 if (tty->packet && tty->link->ctrl_status) 2463 2451 mask |= POLLPRI | POLLIN | POLLRDNORM; 2464 - if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) 2465 - mask |= POLLHUP; 2466 2452 if (tty_hung_up_p(file)) 2467 2453 mask |= POLLHUP; 2468 2454 if (!(mask & (POLLHUP | POLLIN | POLLRDNORM))) {
+3 -2
drivers/tty/pty.c
··· 53 53 /* Review - krefs on tty_link ?? */ 54 54 if (!tty->link) 55 55 return; 56 - tty_flush_to_ldisc(tty->link); 57 56 set_bit(TTY_OTHER_CLOSED, &tty->link->flags); 58 - wake_up_interruptible(&tty->link->read_wait); 57 + tty_flip_buffer_push(tty->link->port); 59 58 wake_up_interruptible(&tty->link->write_wait); 60 59 if (tty->driver->subtype == PTY_TYPE_MASTER) { 61 60 set_bit(TTY_OTHER_CLOSED, &tty->flags); ··· 242 243 goto out; 243 244 244 245 clear_bit(TTY_IO_ERROR, &tty->flags); 246 + /* TTY_OTHER_CLOSED must be cleared before TTY_OTHER_DONE */ 245 247 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags); 248 + clear_bit(TTY_OTHER_DONE, &tty->link->flags); 246 249 set_bit(TTY_THROTTLED, &tty->flags); 247 250 return 0; 248 251
+4 -1
drivers/tty/serial/amba-pl011.c
··· 1639 1639 1640 1640 writew(uap->vendor->ifls, uap->port.membase + UART011_IFLS); 1641 1641 1642 + /* Assume that TX IRQ doesn't work until we see one: */ 1643 + uap->tx_irq_seen = 0; 1644 + 1642 1645 spin_lock_irq(&uap->port.lock); 1643 1646 1644 1647 /* restore RTS and DTR */ ··· 1705 1702 spin_lock_irq(&uap->port.lock); 1706 1703 uap->im = 0; 1707 1704 writew(uap->im, uap->port.membase + UART011_IMSC); 1708 - writew(0xffff & ~UART011_TXIS, uap->port.membase + UART011_ICR); 1705 + writew(0xffff, uap->port.membase + UART011_ICR); 1709 1706 spin_unlock_irq(&uap->port.lock); 1710 1707 1711 1708 pl011_dma_shutdown(uap);
+2 -7
drivers/tty/serial/earlycon.c
··· 187 187 return 0; 188 188 189 189 err = setup_earlycon(buf); 190 - if (err == -ENOENT) { 191 - pr_warn("no match for %s\n", buf); 192 - err = 0; 193 - } else if (err == -EALREADY) { 194 - pr_warn("already registered\n"); 195 - err = 0; 196 - } 190 + if (err == -ENOENT || err == -EALREADY) 191 + return 0; 197 192 return err; 198 193 } 199 194 early_param("earlycon", param_setup_earlycon);
+2
drivers/tty/serial/omap-serial.c
··· 1735 1735 err_add_port: 1736 1736 pm_runtime_put(&pdev->dev); 1737 1737 pm_runtime_disable(&pdev->dev); 1738 + pm_qos_remove_request(&up->pm_qos_request); 1739 + device_init_wakeup(up->dev, false); 1738 1740 err_rs485: 1739 1741 err_port_line: 1740 1742 return ret;
+27 -14
drivers/tty/tty_buffer.c
··· 37 37 38 38 #define TTY_BUFFER_PAGE (((PAGE_SIZE - sizeof(struct tty_buffer)) / 2) & ~0xFF) 39 39 40 + /* 41 + * If all tty flip buffers have been processed by flush_to_ldisc() or 42 + * dropped by tty_buffer_flush(), check if the linked pty has been closed. 43 + * If so, wake the reader/poll to process 44 + */ 45 + static inline void check_other_closed(struct tty_struct *tty) 46 + { 47 + unsigned long flags, old; 48 + 49 + /* transition from TTY_OTHER_CLOSED => TTY_OTHER_DONE must be atomic */ 50 + for (flags = ACCESS_ONCE(tty->flags); 51 + test_bit(TTY_OTHER_CLOSED, &flags); 52 + ) { 53 + old = flags; 54 + __set_bit(TTY_OTHER_DONE, &flags); 55 + flags = cmpxchg(&tty->flags, old, flags); 56 + if (old == flags) { 57 + wake_up_interruptible(&tty->read_wait); 58 + break; 59 + } 60 + } 61 + } 40 62 41 63 /** 42 64 * tty_buffer_lock_exclusive - gain exclusive access to buffer ··· 250 228 251 229 if (ld && ld->ops->flush_buffer) 252 230 ld->ops->flush_buffer(tty); 231 + 232 + check_other_closed(tty); 253 233 254 234 atomic_dec(&buf->priority); 255 235 mutex_unlock(&buf->lock); ··· 495 471 smp_rmb(); 496 472 count = head->commit - head->read; 497 473 if (!count) { 498 - if (next == NULL) 474 + if (next == NULL) { 475 + check_other_closed(tty); 499 476 break; 477 + } 500 478 buf->head = next; 501 479 tty_buffer_free(port, head); 502 480 continue; ··· 512 486 mutex_unlock(&buf->lock); 513 487 514 488 tty_ldisc_deref(disc); 515 - } 516 - 517 - /** 518 - * tty_flush_to_ldisc 519 - * @tty: tty to push 520 - * 521 - * Push the terminal flip buffers to the line discipline. 522 - * 523 - * Must not be called from IRQ context. 524 - */ 525 - void tty_flush_to_ldisc(struct tty_struct *tty) 526 - { 527 - flush_work(&tty->port->buf.work); 528 489 } 529 490 530 491 /**
+1 -1
include/linux/tty.h
··· 339 339 #define TTY_EXCLUSIVE 3 /* Exclusive open mode */ 340 340 #define TTY_DEBUG 4 /* Debugging */ 341 341 #define TTY_DO_WRITE_WAKEUP 5 /* Call write_wakeup after queuing new */ 342 + #define TTY_OTHER_DONE 6 /* Closed pty has completed input processing */ 342 343 #define TTY_LDISC_OPEN 11 /* Line discipline is open */ 343 344 #define TTY_PTY_LOCK 16 /* pty private */ 344 345 #define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */ ··· 463 462 extern void do_SAK(struct tty_struct *tty); 464 463 extern void __do_SAK(struct tty_struct *tty); 465 464 extern void no_tty(void); 466 - extern void tty_flush_to_ldisc(struct tty_struct *tty); 467 465 extern void tty_buffer_free_all(struct tty_port *port); 468 466 extern void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld); 469 467 extern void tty_buffer_init(struct tty_port *port);