Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Revert "tty: make receive_buf() return the amout of bytes received"

This reverts commit b1c43f82c5aa265442f82dba31ce985ebb7aa71c.

It was broken in so many ways, and results in random odd pty issues.

It re-introduced the buggy schedule_work() in flush_to_ldisc() that can
cause endless work-loops (see commit a5660b41af6a: "tty: fix endless
work loop when the buffer fills up").

It also used an "unsigned int" return value fo the ->receive_buf()
function, but then made multiple functions return a negative error code,
and didn't actually check for the error in the caller.

And it didn't actually work at all. BenH bisected down odd tty behavior
to it:
"It looks like the patch is causing some major malfunctions of the X
server for me, possibly related to PTYs. For example, cat'ing a
large file in a gnome terminal hangs the kernel for -minutes- in a
loop of what looks like flush_to_ldisc/workqueue code, (some ftrace
data in the quoted bits further down).

...

Some more data: It -looks- like what happens is that the
flush_to_ldisc work queue entry constantly re-queues itself (because
the PTY is full ?) and the workqueue thread will basically loop
forver calling it without ever scheduling, thus starving the consumer
process that could have emptied the PTY."

which is pretty much exactly the problem we fixed in a5660b41af6a.

Milton Miller pointed out the 'unsigned int' issue.

Reported-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reported-by: Milton Miller <miltonm@bga.com>
Cc: Stefan Bigler <stefan.bigler@keymile.com>
Cc: Toby Gray <toby.gray@realvnc.com>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+115 -128
+6 -11
drivers/bluetooth/hci_ldisc.c
··· 355 355 * flags pointer to flags for data 356 356 * count count of received data in bytes 357 357 * 358 - * Return Value: Number of bytes received 358 + * Return Value: None 359 359 */ 360 - static unsigned int hci_uart_tty_receive(struct tty_struct *tty, 361 - const u8 *data, char *flags, int count) 360 + static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data, char *flags, int count) 362 361 { 363 362 struct hci_uart *hu = (void *)tty->disc_data; 364 - int received; 365 363 366 364 if (!hu || tty != hu->tty) 367 - return -ENODEV; 365 + return; 368 366 369 367 if (!test_bit(HCI_UART_PROTO_SET, &hu->flags)) 370 - return -EINVAL; 368 + return; 371 369 372 370 spin_lock(&hu->rx_lock); 373 - received = hu->proto->recv(hu, (void *) data, count); 374 - if (received > 0) 375 - hu->hdev->stat.byte_rx += received; 371 + hu->proto->recv(hu, (void *) data, count); 372 + hu->hdev->stat.byte_rx += count; 376 373 spin_unlock(&hu->rx_lock); 377 374 378 375 tty_unthrottle(tty); 379 - 380 - return received; 381 376 } 382 377 383 378 static int hci_uart_register_dev(struct hci_uart *hu)
+2 -8
drivers/input/serio/serport.c
··· 120 120 * 'interrupt' routine. 121 121 */ 122 122 123 - static unsigned int serport_ldisc_receive(struct tty_struct *tty, 124 - const unsigned char *cp, char *fp, int count) 123 + static void serport_ldisc_receive(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) 125 124 { 126 125 struct serport *serport = (struct serport*) tty->disc_data; 127 126 unsigned long flags; 128 127 unsigned int ch_flags; 129 - int ret = 0; 130 128 int i; 131 129 132 130 spin_lock_irqsave(&serport->lock, flags); 133 131 134 - if (!test_bit(SERPORT_ACTIVE, &serport->flags)) { 135 - ret = -EINVAL; 132 + if (!test_bit(SERPORT_ACTIVE, &serport->flags)) 136 133 goto out; 137 - } 138 134 139 135 for (i = 0; i < count; i++) { 140 136 switch (fp[i]) { ··· 152 156 153 157 out: 154 158 spin_unlock_irqrestore(&serport->lock, flags); 155 - 156 - return ret == 0 ? count : ret; 157 159 } 158 160 159 161 /*
+3 -5
drivers/isdn/gigaset/ser-gigaset.c
··· 674 674 * cflags buffer containing error flags for received characters (ignored) 675 675 * count number of received characters 676 676 */ 677 - static unsigned int 677 + static void 678 678 gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf, 679 679 char *cflags, int count) 680 680 { ··· 683 683 struct inbuf_t *inbuf; 684 684 685 685 if (!cs) 686 - return -ENODEV; 686 + return; 687 687 inbuf = cs->inbuf; 688 688 if (!inbuf) { 689 689 dev_err(cs->dev, "%s: no inbuf\n", __func__); 690 690 cs_put(cs); 691 - return -EINVAL; 691 + return; 692 692 } 693 693 694 694 tail = inbuf->tail; ··· 725 725 gig_dbg(DEBUG_INTR, "%s-->BH", __func__); 726 726 gigaset_schedule_event(cs); 727 727 cs_put(cs); 728 - 729 - return count; 730 728 } 731 729 732 730 /*
+2 -4
drivers/misc/ti-st/st_core.c
··· 747 747 pr_debug("%s: done ", __func__); 748 748 } 749 749 750 - static unsigned int st_tty_receive(struct tty_struct *tty, 751 - const unsigned char *data, char *tty_flags, int count) 750 + static void st_tty_receive(struct tty_struct *tty, const unsigned char *data, 751 + char *tty_flags, int count) 752 752 { 753 753 #ifdef VERBOSE 754 754 print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE, ··· 761 761 */ 762 762 st_recv(tty->disc_data, data, count); 763 763 pr_debug("done %s", __func__); 764 - 765 - return count; 766 764 } 767 765 768 766 /* wake-up function called in from the TTY layer
+2 -4
drivers/net/caif/caif_serial.c
··· 167 167 168 168 #endif 169 169 170 - static unsigned int ldisc_receive(struct tty_struct *tty, 171 - const u8 *data, char *flags, int count) 170 + static void ldisc_receive(struct tty_struct *tty, const u8 *data, 171 + char *flags, int count) 172 172 { 173 173 struct sk_buff *skb = NULL; 174 174 struct ser_device *ser; ··· 215 215 } else 216 216 ++ser->dev->stats.rx_dropped; 217 217 update_tty_status(ser); 218 - 219 - return count; 220 218 } 221 219 222 220 static int handle_tx(struct ser_device *ser)
+3 -6
drivers/net/can/slcan.c
··· 425 425 * in parallel 426 426 */ 427 427 428 - static unsigned int slcan_receive_buf(struct tty_struct *tty, 428 + static void slcan_receive_buf(struct tty_struct *tty, 429 429 const unsigned char *cp, char *fp, int count) 430 430 { 431 431 struct slcan *sl = (struct slcan *) tty->disc_data; 432 - int bytes = count; 433 432 434 433 if (!sl || sl->magic != SLCAN_MAGIC || !netif_running(sl->dev)) 435 - return -ENODEV; 434 + return; 436 435 437 436 /* Read the characters out of the buffer */ 438 - while (bytes--) { 437 + while (count--) { 439 438 if (fp && *fp++) { 440 439 if (!test_and_set_bit(SLF_ERROR, &sl->flags)) 441 440 sl->dev->stats.rx_errors++; ··· 443 444 } 444 445 slcan_unesc(sl, *cp++); 445 446 } 446 - 447 - return count; 448 447 } 449 448 450 449 /************************************
+3 -5
drivers/net/hamradio/6pack.c
··· 456 456 * a block of 6pack data has been received, which can now be decapsulated 457 457 * and sent on to some IP layer for further processing. 458 458 */ 459 - static unsigned int sixpack_receive_buf(struct tty_struct *tty, 459 + static void sixpack_receive_buf(struct tty_struct *tty, 460 460 const unsigned char *cp, char *fp, int count) 461 461 { 462 462 struct sixpack *sp; ··· 464 464 int count1; 465 465 466 466 if (!count) 467 - return 0; 467 + return; 468 468 469 469 sp = sp_get(tty); 470 470 if (!sp) 471 - return -ENODEV; 471 + return; 472 472 473 473 memcpy(buf, cp, count < sizeof(buf) ? count : sizeof(buf)); 474 474 ··· 487 487 488 488 sp_put(sp); 489 489 tty_unthrottle(tty); 490 - 491 - return count1; 492 490 } 493 491 494 492 /*
+4 -7
drivers/net/hamradio/mkiss.c
··· 923 923 * a block of data has been received, which can now be decapsulated 924 924 * and sent on to the AX.25 layer for further processing. 925 925 */ 926 - static unsigned int mkiss_receive_buf(struct tty_struct *tty, 927 - const unsigned char *cp, char *fp, int count) 926 + static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp, 927 + char *fp, int count) 928 928 { 929 929 struct mkiss *ax = mkiss_get(tty); 930 - int bytes = count; 931 930 932 931 if (!ax) 933 - return -ENODEV; 932 + return; 934 933 935 934 /* 936 935 * Argh! mtu change time! - costs us the packet part received ··· 939 940 ax_changedmtu(ax); 940 941 941 942 /* Read the characters out of the buffer */ 942 - while (bytes--) { 943 + while (count--) { 943 944 if (fp != NULL && *fp++) { 944 945 if (!test_and_set_bit(AXF_ERROR, &ax->flags)) 945 946 ax->dev->stats.rx_errors++; ··· 952 953 953 954 mkiss_put(ax); 954 955 tty_unthrottle(tty); 955 - 956 - return count; 957 956 } 958 957 959 958 /*
+7 -9
drivers/net/irda/irtty-sir.c
··· 216 216 * usbserial: urb-complete-interrupt / softint 217 217 */ 218 218 219 - static unsigned int irtty_receive_buf(struct tty_struct *tty, 220 - const unsigned char *cp, char *fp, int count) 219 + static void irtty_receive_buf(struct tty_struct *tty, const unsigned char *cp, 220 + char *fp, int count) 221 221 { 222 222 struct sir_dev *dev; 223 223 struct sirtty_cb *priv = tty->disc_data; 224 224 int i; 225 225 226 - IRDA_ASSERT(priv != NULL, return -ENODEV;); 227 - IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -EINVAL;); 226 + IRDA_ASSERT(priv != NULL, return;); 227 + IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return;); 228 228 229 229 if (unlikely(count==0)) /* yes, this happens */ 230 - return 0; 230 + return; 231 231 232 232 dev = priv->dev; 233 233 if (!dev) { 234 234 IRDA_WARNING("%s(), not ready yet!\n", __func__); 235 - return -ENODEV; 235 + return; 236 236 } 237 237 238 238 for (i = 0; i < count; i++) { ··· 242 242 if (fp && *fp++) { 243 243 IRDA_DEBUG(0, "Framing or parity error!\n"); 244 244 sirdev_receive(dev, NULL, 0); /* notify sir_dev (updating stats) */ 245 - return -EINVAL; 245 + return; 246 246 } 247 247 } 248 248 249 249 sirdev_receive(dev, cp, count); 250 - 251 - return count; 252 250 } 253 251 254 252 /*
+2 -4
drivers/net/ppp_async.c
··· 340 340 } 341 341 342 342 /* May sleep, don't call from interrupt level or with interrupts disabled */ 343 - static unsigned int 343 + static void 344 344 ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf, 345 345 char *cflags, int count) 346 346 { ··· 348 348 unsigned long flags; 349 349 350 350 if (!ap) 351 - return -ENODEV; 351 + return; 352 352 spin_lock_irqsave(&ap->recv_lock, flags); 353 353 ppp_async_input(ap, buf, cflags, count); 354 354 spin_unlock_irqrestore(&ap->recv_lock, flags); ··· 356 356 tasklet_schedule(&ap->tsk); 357 357 ap_put(ap); 358 358 tty_unthrottle(tty); 359 - 360 - return count; 361 359 } 362 360 363 361 static void
+2 -4
drivers/net/ppp_synctty.c
··· 381 381 } 382 382 383 383 /* May sleep, don't call from interrupt level or with interrupts disabled */ 384 - static unsigned int 384 + static void 385 385 ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf, 386 386 char *cflags, int count) 387 387 { ··· 389 389 unsigned long flags; 390 390 391 391 if (!ap) 392 - return -ENODEV; 392 + return; 393 393 spin_lock_irqsave(&ap->recv_lock, flags); 394 394 ppp_sync_input(ap, buf, cflags, count); 395 395 spin_unlock_irqrestore(&ap->recv_lock, flags); ··· 397 397 tasklet_schedule(&ap->tsk); 398 398 sp_put(ap); 399 399 tty_unthrottle(tty); 400 - 401 - return count; 402 400 } 403 401 404 402 static void
+4 -7
drivers/net/slip.c
··· 670 670 * in parallel 671 671 */ 672 672 673 - static unsigned int slip_receive_buf(struct tty_struct *tty, 674 - const unsigned char *cp, char *fp, int count) 673 + static void slip_receive_buf(struct tty_struct *tty, const unsigned char *cp, 674 + char *fp, int count) 675 675 { 676 676 struct slip *sl = tty->disc_data; 677 - int bytes = count; 678 677 679 678 if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev)) 680 - return -ENODEV; 679 + return; 681 680 682 681 /* Read the characters out of the buffer */ 683 - while (bytes--) { 682 + while (count--) { 684 683 if (fp && *fp++) { 685 684 if (!test_and_set_bit(SLF_ERROR, &sl->flags)) 686 685 sl->dev->stats.rx_errors++; ··· 693 694 #endif 694 695 slip_unesc(sl, *cp++); 695 696 } 696 - 697 - return count; 698 697 } 699 698 700 699 /************************************
+2 -5
drivers/net/wan/x25_asy.c
··· 517 517 * and sent on to some IP layer for further processing. 518 518 */ 519 519 520 - static unsigned int x25_asy_receive_buf(struct tty_struct *tty, 520 + static void x25_asy_receive_buf(struct tty_struct *tty, 521 521 const unsigned char *cp, char *fp, int count) 522 522 { 523 523 struct x25_asy *sl = tty->disc_data; 524 - int bytes = count; 525 524 526 525 if (!sl || sl->magic != X25_ASY_MAGIC || !netif_running(sl->dev)) 527 526 return; 528 527 529 528 530 529 /* Read the characters out of the buffer */ 531 - while (bytes--) { 530 + while (count--) { 532 531 if (fp && *fp++) { 533 532 if (!test_and_set_bit(SLF_ERROR, &sl->flags)) 534 533 sl->dev->stats.rx_errors++; ··· 536 537 } 537 538 x25_asy_unesc(sl, *cp++); 538 539 } 539 - 540 - return count; 541 540 } 542 541 543 542 /*
+2 -4
drivers/tty/n_gsm.c
··· 2128 2128 gsm->tty = NULL; 2129 2129 } 2130 2130 2131 - static unsigned int gsmld_receive_buf(struct tty_struct *tty, 2132 - const unsigned char *cp, char *fp, int count) 2131 + static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp, 2132 + char *fp, int count) 2133 2133 { 2134 2134 struct gsm_mux *gsm = tty->disc_data; 2135 2135 const unsigned char *dp; ··· 2162 2162 } 2163 2163 /* FASYNC if needed ? */ 2164 2164 /* If clogged call tty_throttle(tty); */ 2165 - 2166 - return count; 2167 2165 } 2168 2166 2169 2167 /**
+8 -10
drivers/tty/n_hdlc.c
··· 188 188 poll_table *wait); 189 189 static int n_hdlc_tty_open(struct tty_struct *tty); 190 190 static void n_hdlc_tty_close(struct tty_struct *tty); 191 - static unsigned int n_hdlc_tty_receive(struct tty_struct *tty, 192 - const __u8 *cp, char *fp, int count); 191 + static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *cp, 192 + char *fp, int count); 193 193 static void n_hdlc_tty_wakeup(struct tty_struct *tty); 194 194 195 195 #define bset(p,b) ((p)[(b) >> 5] |= (1 << ((b) & 0x1f))) ··· 509 509 * Called by tty low level driver when receive data is available. Data is 510 510 * interpreted as one HDLC frame. 511 511 */ 512 - static unsigned int n_hdlc_tty_receive(struct tty_struct *tty, 513 - const __u8 *data, char *flags, int count) 512 + static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data, 513 + char *flags, int count) 514 514 { 515 515 register struct n_hdlc *n_hdlc = tty2n_hdlc (tty); 516 516 register struct n_hdlc_buf *buf; ··· 521 521 522 522 /* This can happen if stuff comes in on the backup tty */ 523 523 if (!n_hdlc || tty != n_hdlc->tty) 524 - return -ENODEV; 524 + return; 525 525 526 526 /* verify line is using HDLC discipline */ 527 527 if (n_hdlc->magic != HDLC_MAGIC) { 528 528 printk("%s(%d) line not using HDLC discipline\n", 529 529 __FILE__,__LINE__); 530 - return -EINVAL; 530 + return; 531 531 } 532 532 533 533 if ( count>maxframe ) { 534 534 if (debuglevel >= DEBUG_LEVEL_INFO) 535 535 printk("%s(%d) rx count>maxframesize, data discarded\n", 536 536 __FILE__,__LINE__); 537 - return -EINVAL; 537 + return; 538 538 } 539 539 540 540 /* get a free HDLC buffer */ ··· 550 550 if (debuglevel >= DEBUG_LEVEL_INFO) 551 551 printk("%s(%d) no more rx buffers, data discarded\n", 552 552 __FILE__,__LINE__); 553 - return -EINVAL; 553 + return; 554 554 } 555 555 556 556 /* copy received data to HDLC buffer */ ··· 564 564 wake_up_interruptible (&tty->read_wait); 565 565 if (n_hdlc->tty->fasync != NULL) 566 566 kill_fasync (&n_hdlc->tty->fasync, SIGIO, POLL_IN); 567 - 568 - return count; 569 567 570 568 } /* end of n_hdlc_tty_receive() */ 571 569
+4 -6
drivers/tty/n_r3964.c
··· 139 139 static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old); 140 140 static unsigned int r3964_poll(struct tty_struct *tty, struct file *file, 141 141 struct poll_table_struct *wait); 142 - static unsigned int r3964_receive_buf(struct tty_struct *tty, 143 - const unsigned char *cp, char *fp, int count); 142 + static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp, 143 + char *fp, int count); 144 144 145 145 static struct tty_ldisc_ops tty_ldisc_N_R3964 = { 146 146 .owner = THIS_MODULE, ··· 1239 1239 return result; 1240 1240 } 1241 1241 1242 - static unsigned int r3964_receive_buf(struct tty_struct *tty, 1243 - const unsigned char *cp, char *fp, int count) 1242 + static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp, 1243 + char *fp, int count) 1244 1244 { 1245 1245 struct r3964_info *pInfo = tty->disc_data; 1246 1246 const unsigned char *p; ··· 1257 1257 } 1258 1258 1259 1259 } 1260 - 1261 - return count; 1262 1260 } 1263 1261 1264 1262 MODULE_LICENSE("GPL");
+47 -14
drivers/tty/n_tty.c
··· 81 81 return put_user(x, ptr); 82 82 } 83 83 84 + /** 85 + * n_tty_set__room - receive space 86 + * @tty: terminal 87 + * 88 + * Called by the driver to find out how much data it is 89 + * permitted to feed to the line discipline without any being lost 90 + * and thus to manage flow control. Not serialized. Answers for the 91 + * "instant". 92 + */ 93 + 94 + static void n_tty_set_room(struct tty_struct *tty) 95 + { 96 + /* tty->read_cnt is not read locked ? */ 97 + int left = N_TTY_BUF_SIZE - tty->read_cnt - 1; 98 + int old_left; 99 + 100 + /* 101 + * If we are doing input canonicalization, and there are no 102 + * pending newlines, let characters through without limit, so 103 + * that erase characters will be handled. Other excess 104 + * characters will be beeped. 105 + */ 106 + if (left <= 0) 107 + left = tty->icanon && !tty->canon_data; 108 + old_left = tty->receive_room; 109 + tty->receive_room = left; 110 + 111 + /* Did this open up the receive buffer? We may need to flip */ 112 + if (left && !old_left) 113 + schedule_work(&tty->buf.work); 114 + } 115 + 84 116 static void put_tty_queue_nolock(unsigned char c, struct tty_struct *tty) 85 117 { 86 118 if (tty->read_cnt < N_TTY_BUF_SIZE) { ··· 184 152 185 153 tty->canon_head = tty->canon_data = tty->erasing = 0; 186 154 memset(&tty->read_flags, 0, sizeof tty->read_flags); 155 + n_tty_set_room(tty); 187 156 check_unthrottle(tty); 188 157 } 189 158 ··· 1360 1327 * calls one at a time and in order (or using flush_to_ldisc) 1361 1328 */ 1362 1329 1363 - static unsigned int n_tty_receive_buf(struct tty_struct *tty, 1364 - const unsigned char *cp, char *fp, int count) 1330 + static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, 1331 + char *fp, int count) 1365 1332 { 1366 1333 const unsigned char *p; 1367 1334 char *f, flags = TTY_NORMAL; 1368 1335 int i; 1369 1336 char buf[64]; 1370 1337 unsigned long cpuflags; 1371 - int left; 1372 - int ret = 0; 1373 1338 1374 1339 if (!tty->read_buf) 1375 - return 0; 1340 + return; 1376 1341 1377 1342 if (tty->real_raw) { 1378 1343 spin_lock_irqsave(&tty->read_lock, cpuflags); ··· 1380 1349 memcpy(tty->read_buf + tty->read_head, cp, i); 1381 1350 tty->read_head = (tty->read_head + i) & (N_TTY_BUF_SIZE-1); 1382 1351 tty->read_cnt += i; 1383 - ret += i; 1384 1352 cp += i; 1385 1353 count -= i; 1386 1354 ··· 1389 1359 memcpy(tty->read_buf + tty->read_head, cp, i); 1390 1360 tty->read_head = (tty->read_head + i) & (N_TTY_BUF_SIZE-1); 1391 1361 tty->read_cnt += i; 1392 - ret += i; 1393 1362 spin_unlock_irqrestore(&tty->read_lock, cpuflags); 1394 1363 } else { 1395 - ret = count; 1396 1364 for (i = count, p = cp, f = fp; i; i--, p++) { 1397 1365 if (f) 1398 1366 flags = *f++; ··· 1418 1390 tty->ops->flush_chars(tty); 1419 1391 } 1420 1392 1393 + n_tty_set_room(tty); 1394 + 1421 1395 if ((!tty->icanon && (tty->read_cnt >= tty->minimum_to_wake)) || 1422 1396 L_EXTPROC(tty)) { 1423 1397 kill_fasync(&tty->fasync, SIGIO, POLL_IN); ··· 1432 1402 * mode. We don't want to throttle the driver if we're in 1433 1403 * canonical mode and don't have a newline yet! 1434 1404 */ 1435 - left = N_TTY_BUF_SIZE - tty->read_cnt - 1; 1436 - 1437 - if (left < TTY_THRESHOLD_THROTTLE) 1405 + if (tty->receive_room < TTY_THRESHOLD_THROTTLE) 1438 1406 tty_throttle(tty); 1439 - 1440 - return ret; 1441 1407 } 1442 1408 1443 1409 int is_ignored(int sig) ··· 1477 1451 if (test_bit(TTY_HW_COOK_IN, &tty->flags)) { 1478 1452 tty->raw = 1; 1479 1453 tty->real_raw = 1; 1454 + n_tty_set_room(tty); 1480 1455 return; 1481 1456 } 1482 1457 if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) || ··· 1530 1503 else 1531 1504 tty->real_raw = 0; 1532 1505 } 1506 + n_tty_set_room(tty); 1533 1507 /* The termios change make the tty ready for I/O */ 1534 1508 wake_up_interruptible(&tty->write_wait); 1535 1509 wake_up_interruptible(&tty->read_wait); ··· 1812 1784 retval = -ERESTARTSYS; 1813 1785 break; 1814 1786 } 1787 + /* FIXME: does n_tty_set_room need locking ? */ 1788 + n_tty_set_room(tty); 1815 1789 timeout = schedule_timeout(timeout); 1816 1790 continue; 1817 1791 } ··· 1885 1855 * longer than TTY_THRESHOLD_UNTHROTTLE in canonical mode, 1886 1856 * we won't get any more characters. 1887 1857 */ 1888 - if (n_tty_chars_in_buffer(tty) <= TTY_THRESHOLD_UNTHROTTLE) 1858 + if (n_tty_chars_in_buffer(tty) <= TTY_THRESHOLD_UNTHROTTLE) { 1859 + n_tty_set_room(tty); 1889 1860 check_unthrottle(tty); 1861 + } 1890 1862 1891 1863 if (b - buf >= minimum) 1892 1864 break; ··· 1910 1878 } else if (test_and_clear_bit(TTY_PUSH, &tty->flags)) 1911 1879 goto do_it_again; 1912 1880 1881 + n_tty_set_room(tty); 1913 1882 return retval; 1914 1883 } 1915 1884
+6 -9
drivers/tty/tty_buffer.c
··· 416 416 struct tty_buffer *head, *tail = tty->buf.tail; 417 417 int seen_tail = 0; 418 418 while ((head = tty->buf.head) != NULL) { 419 - int copied; 420 419 int count; 421 420 char *char_buf; 422 421 unsigned char *flag_buf; ··· 442 443 line discipline as we want to empty the queue */ 443 444 if (test_bit(TTY_FLUSHPENDING, &tty->flags)) 444 445 break; 446 + if (!tty->receive_room || seen_tail) 447 + break; 448 + if (count > tty->receive_room) 449 + count = tty->receive_room; 445 450 char_buf = head->char_buf_ptr + head->read; 446 451 flag_buf = head->flag_buf_ptr + head->read; 452 + head->read += count; 447 453 spin_unlock_irqrestore(&tty->buf.lock, flags); 448 - copied = disc->ops->receive_buf(tty, char_buf, 454 + disc->ops->receive_buf(tty, char_buf, 449 455 flag_buf, count); 450 456 spin_lock_irqsave(&tty->buf.lock, flags); 451 - 452 - head->read += copied; 453 - 454 - if (copied == 0 || seen_tail) { 455 - schedule_work(&tty->buf.work); 456 - break; 457 - } 458 457 } 459 458 clear_bit(TTY_FLUSHING, &tty->flags); 460 459 }
+2 -1
drivers/tty/vt/selection.c
··· 332 332 continue; 333 333 } 334 334 count = sel_buffer_lth - pasted; 335 - count = tty->ldisc->ops->receive_buf(tty, sel_buffer + pasted, 335 + count = min(count, tty->receive_room); 336 + tty->ldisc->ops->receive_buf(tty, sel_buffer + pasted, 336 337 NULL, count); 337 338 pasted += count; 338 339 }
+4 -5
include/linux/tty_ldisc.h
··· 76 76 * tty device. It is solely the responsibility of the line 77 77 * discipline to handle poll requests. 78 78 * 79 - * unsigned int (*receive_buf)(struct tty_struct *, const unsigned char *cp, 79 + * void (*receive_buf)(struct tty_struct *, const unsigned char *cp, 80 80 * char *fp, int count); 81 81 * 82 82 * This function is called by the low-level tty driver to send ··· 84 84 * processing. <cp> is a pointer to the buffer of input 85 85 * character received by the device. <fp> is a pointer to a 86 86 * pointer of flag bytes which indicate whether a character was 87 - * received with a parity error, etc. Returns the amount of bytes 88 - * received. 87 + * received with a parity error, etc. 89 88 * 90 89 * void (*write_wakeup)(struct tty_struct *); 91 90 * ··· 140 141 /* 141 142 * The following routines are called from below. 142 143 */ 143 - unsigned int (*receive_buf)(struct tty_struct *, 144 - const unsigned char *cp, char *fp, int count); 144 + void (*receive_buf)(struct tty_struct *, const unsigned char *cp, 145 + char *fp, int count); 145 146 void (*write_wakeup)(struct tty_struct *); 146 147 void (*dcd_change)(struct tty_struct *, unsigned int, 147 148 struct pps_event_time *);