Skip to content

Commit 55db4c6

Browse files
committed
Revert "tty: make receive_buf() return the amout of bytes received"
This reverts commit b1c43f8. 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 a5660b4: "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 a5660b4. 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>
1 parent 1fa7b6a commit 55db4c6

20 files changed

Lines changed: 115 additions & 128 deletions

File tree

‎drivers/bluetooth/hci_ldisc.c‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,29 +355,24 @@ static void hci_uart_tty_wakeup(struct tty_struct *tty)
355355
* flags pointer to flags for data
356356
* count count of received data in bytes
357357
*
358-
* Return Value: Number of bytes received
358+
* Return Value: None
359359
*/
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)
362361
{
363362
struct hci_uart *hu = (void *)tty->disc_data;
364-
int received;
365363

366364
if (!hu || tty != hu->tty)
367-
return -ENODEV;
365+
return;
368366

369367
if (!test_bit(HCI_UART_PROTO_SET, &hu->flags))
370-
return -EINVAL;
368+
return;
371369

372370
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;
376373
spin_unlock(&hu->rx_lock);
377374

378375
tty_unthrottle(tty);
379-
380-
return received;
381376
}
382377

383378
static int hci_uart_register_dev(struct hci_uart *hu)

‎drivers/input/serio/serport.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,17 @@ static void serport_ldisc_close(struct tty_struct *tty)
120120
* 'interrupt' routine.
121121
*/
122122

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)
125124
{
126125
struct serport *serport = (struct serport*) tty->disc_data;
127126
unsigned long flags;
128127
unsigned int ch_flags;
129-
int ret = 0;
130128
int i;
131129

132130
spin_lock_irqsave(&serport->lock, flags);
133131

134-
if (!test_bit(SERPORT_ACTIVE, &serport->flags)) {
135-
ret = -EINVAL;
132+
if (!test_bit(SERPORT_ACTIVE, &serport->flags))
136133
goto out;
137-
}
138134

139135
for (i = 0; i < count; i++) {
140136
switch (fp[i]) {
@@ -156,8 +152,6 @@ static unsigned int serport_ldisc_receive(struct tty_struct *tty,
156152

157153
out:
158154
spin_unlock_irqrestore(&serport->lock, flags);
159-
160-
return ret == 0 ? count : ret;
161155
}
162156

163157
/*

‎drivers/isdn/gigaset/ser-gigaset.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ gigaset_tty_ioctl(struct tty_struct *tty, struct file *file,
674674
* cflags buffer containing error flags for received characters (ignored)
675675
* count number of received characters
676676
*/
677-
static unsigned int
677+
static void
678678
gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf,
679679
char *cflags, int count)
680680
{
@@ -683,12 +683,12 @@ gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf,
683683
struct inbuf_t *inbuf;
684684

685685
if (!cs)
686-
return -ENODEV;
686+
return;
687687
inbuf = cs->inbuf;
688688
if (!inbuf) {
689689
dev_err(cs->dev, "%s: no inbuf\n", __func__);
690690
cs_put(cs);
691-
return -EINVAL;
691+
return;
692692
}
693693

694694
tail = inbuf->tail;
@@ -725,8 +725,6 @@ gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf,
725725
gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
726726
gigaset_schedule_event(cs);
727727
cs_put(cs);
728-
729-
return count;
730728
}
731729

732730
/*

‎drivers/misc/ti-st/st_core.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ static void st_tty_close(struct tty_struct *tty)
747747
pr_debug("%s: done ", __func__);
748748
}
749749

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)
752752
{
753753
#ifdef VERBOSE
754754
print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE,
@@ -761,8 +761,6 @@ static unsigned int st_tty_receive(struct tty_struct *tty,
761761
*/
762762
st_recv(tty->disc_data, data, count);
763763
pr_debug("done %s", __func__);
764-
765-
return count;
766764
}
767765

768766
/* wake-up function called in from the TTY layer

‎drivers/net/caif/caif_serial.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ static inline void debugfs_tx(struct ser_device *ser, const u8 *data, int size)
167167

168168
#endif
169169

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)
172172
{
173173
struct sk_buff *skb = NULL;
174174
struct ser_device *ser;
@@ -215,8 +215,6 @@ static unsigned int ldisc_receive(struct tty_struct *tty,
215215
} else
216216
++ser->dev->stats.rx_dropped;
217217
update_tty_status(ser);
218-
219-
return count;
220218
}
221219

222220
static int handle_tx(struct ser_device *ser)

‎drivers/net/can/slcan.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,16 @@ static void slc_setup(struct net_device *dev)
425425
* in parallel
426426
*/
427427

428-
static unsigned int slcan_receive_buf(struct tty_struct *tty,
428+
static void slcan_receive_buf(struct tty_struct *tty,
429429
const unsigned char *cp, char *fp, int count)
430430
{
431431
struct slcan *sl = (struct slcan *) tty->disc_data;
432-
int bytes = count;
433432

434433
if (!sl || sl->magic != SLCAN_MAGIC || !netif_running(sl->dev))
435-
return -ENODEV;
434+
return;
436435

437436
/* Read the characters out of the buffer */
438-
while (bytes--) {
437+
while (count--) {
439438
if (fp && *fp++) {
440439
if (!test_and_set_bit(SLF_ERROR, &sl->flags))
441440
sl->dev->stats.rx_errors++;
@@ -444,8 +443,6 @@ static unsigned int slcan_receive_buf(struct tty_struct *tty,
444443
}
445444
slcan_unesc(sl, *cp++);
446445
}
447-
448-
return count;
449446
}
450447

451448
/************************************

‎drivers/net/hamradio/6pack.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,19 +456,19 @@ static void sixpack_write_wakeup(struct tty_struct *tty)
456456
* a block of 6pack data has been received, which can now be decapsulated
457457
* and sent on to some IP layer for further processing.
458458
*/
459-
static unsigned int sixpack_receive_buf(struct tty_struct *tty,
459+
static void sixpack_receive_buf(struct tty_struct *tty,
460460
const unsigned char *cp, char *fp, int count)
461461
{
462462
struct sixpack *sp;
463463
unsigned char buf[512];
464464
int count1;
465465

466466
if (!count)
467-
return 0;
467+
return;
468468

469469
sp = sp_get(tty);
470470
if (!sp)
471-
return -ENODEV;
471+
return;
472472

473473
memcpy(buf, cp, count < sizeof(buf) ? count : sizeof(buf));
474474

@@ -487,8 +487,6 @@ static unsigned int sixpack_receive_buf(struct tty_struct *tty,
487487

488488
sp_put(sp);
489489
tty_unthrottle(tty);
490-
491-
return count1;
492490
}
493491

494492
/*

‎drivers/net/hamradio/mkiss.c‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -923,14 +923,13 @@ static long mkiss_compat_ioctl(struct tty_struct *tty, struct file *file,
923923
* a block of data has been received, which can now be decapsulated
924924
* and sent on to the AX.25 layer for further processing.
925925
*/
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)
928928
{
929929
struct mkiss *ax = mkiss_get(tty);
930-
int bytes = count;
931930

932931
if (!ax)
933-
return -ENODEV;
932+
return;
934933

935934
/*
936935
* Argh! mtu change time! - costs us the packet part received
@@ -940,7 +939,7 @@ static unsigned int mkiss_receive_buf(struct tty_struct *tty,
940939
ax_changedmtu(ax);
941940

942941
/* Read the characters out of the buffer */
943-
while (bytes--) {
942+
while (count--) {
944943
if (fp != NULL && *fp++) {
945944
if (!test_and_set_bit(AXF_ERROR, &ax->flags))
946945
ax->dev->stats.rx_errors++;
@@ -953,8 +952,6 @@ static unsigned int mkiss_receive_buf(struct tty_struct *tty,
953952

954953
mkiss_put(ax);
955954
tty_unthrottle(tty);
956-
957-
return count;
958955
}
959956

960957
/*

‎drivers/net/irda/irtty-sir.c‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,23 +216,23 @@ static int irtty_do_write(struct sir_dev *dev, const unsigned char *ptr, size_t
216216
* usbserial: urb-complete-interrupt / softint
217217
*/
218218

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)
221221
{
222222
struct sir_dev *dev;
223223
struct sirtty_cb *priv = tty->disc_data;
224224
int i;
225225

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;);
228228

229229
if (unlikely(count==0)) /* yes, this happens */
230-
return 0;
230+
return;
231231

232232
dev = priv->dev;
233233
if (!dev) {
234234
IRDA_WARNING("%s(), not ready yet!\n", __func__);
235-
return -ENODEV;
235+
return;
236236
}
237237

238238
for (i = 0; i < count; i++) {
@@ -242,13 +242,11 @@ static unsigned int irtty_receive_buf(struct tty_struct *tty,
242242
if (fp && *fp++) {
243243
IRDA_DEBUG(0, "Framing or parity error!\n");
244244
sirdev_receive(dev, NULL, 0); /* notify sir_dev (updating stats) */
245-
return -EINVAL;
245+
return;
246246
}
247247
}
248248

249249
sirdev_receive(dev, cp, count);
250-
251-
return count;
252250
}
253251

254252
/*

‎drivers/net/ppp_async.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,24 +340,22 @@ ppp_asynctty_poll(struct tty_struct *tty, struct file *file, poll_table *wait)
340340
}
341341

342342
/* May sleep, don't call from interrupt level or with interrupts disabled */
343-
static unsigned int
343+
static void
344344
ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf,
345345
char *cflags, int count)
346346
{
347347
struct asyncppp *ap = ap_get(tty);
348348
unsigned long flags;
349349

350350
if (!ap)
351-
return -ENODEV;
351+
return;
352352
spin_lock_irqsave(&ap->recv_lock, flags);
353353
ppp_async_input(ap, buf, cflags, count);
354354
spin_unlock_irqrestore(&ap->recv_lock, flags);
355355
if (!skb_queue_empty(&ap->rqueue))
356356
tasklet_schedule(&ap->tsk);
357357
ap_put(ap);
358358
tty_unthrottle(tty);
359-
360-
return count;
361359
}
362360

363361
static void

0 commit comments

Comments
 (0)