Skip to content

Commit b1c43f8

Browse files
Felipe Balbigregkh
authored andcommitted
tty: make receive_buf() return the amout of bytes received
it makes it simpler to keep track of the amount of bytes received and simplifies how flush_to_ldisc counts the remaining bytes. It also fixes a bug of lost bytes on n_tty when flushing too many bytes via the USB serial gadget driver. Tested-by: Stefan Bigler <stefan.bigler@keymile.com> Tested-by: Toby Gray <toby.gray@realvnc.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent e9a470f commit b1c43f8

20 files changed

Lines changed: 125 additions & 113 deletions

File tree

‎drivers/bluetooth/hci_ldisc.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,22 +357,26 @@ static void hci_uart_tty_wakeup(struct tty_struct *tty)
357357
*
358358
* Return Value: None
359359
*/
360-
static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data, char *flags, int count)
360+
static unsigned int hci_uart_tty_receive(struct tty_struct *tty,
361+
const u8 *data, char *flags, int count)
361362
{
362363
struct hci_uart *hu = (void *)tty->disc_data;
364+
int received;
363365

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

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

370372
spin_lock(&hu->rx_lock);
371-
hu->proto->recv(hu, (void *) data, count);
373+
received = hu->proto->recv(hu, (void *) data, count);
372374
hu->hdev->stat.byte_rx += count;
373375
spin_unlock(&hu->rx_lock);
374376

375377
tty_unthrottle(tty);
378+
379+
return received;
376380
}
377381

378382
static int hci_uart_register_dev(struct hci_uart *hu)

‎drivers/input/serio/serport.c‎

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

123-
static void serport_ldisc_receive(struct tty_struct *tty, const unsigned char *cp, char *fp, int count)
123+
static unsigned int serport_ldisc_receive(struct tty_struct *tty,
124+
const unsigned char *cp, char *fp, int count)
124125
{
125126
struct serport *serport = (struct serport*) tty->disc_data;
126127
unsigned long flags;
127128
unsigned int ch_flags;
129+
int ret = 0;
128130
int i;
129131

130132
spin_lock_irqsave(&serport->lock, flags);
131133

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

135139
for (i = 0; i < count; i++) {
136140
switch (fp[i]) {
@@ -152,6 +156,8 @@ static void serport_ldisc_receive(struct tty_struct *tty, const unsigned char *c
152156

153157
out:
154158
spin_unlock_irqrestore(&serport->lock, flags);
159+
160+
return ret == 0 ? count : ret;
155161
}
156162

157163
/*

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

Lines changed: 5 additions & 3 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 void
677+
static unsigned int
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;
686+
return -ENODEV;
687687
inbuf = cs->inbuf;
688688
if (!inbuf) {
689689
dev_err(cs->dev, "%s: no inbuf\n", __func__);
690690
cs_put(cs);
691-
return;
691+
return -EINVAL;
692692
}
693693

694694
tail = inbuf->tail;
@@ -725,6 +725,8 @@ 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;
728730
}
729731

730732
/*

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

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

747-
static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
748-
char *tty_flags, int count)
747+
static unsigned int st_tty_receive(struct tty_struct *tty,
748+
const unsigned char *data, char *tty_flags, int count)
749749
{
750750
#ifdef VERBOSE
751751
print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE,
@@ -758,6 +758,8 @@ static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
758758
*/
759759
st_recv(tty->disc_data, data, count);
760760
pr_debug("done %s", __func__);
761+
762+
return count;
761763
}
762764

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

‎drivers/net/caif/caif_serial.c‎

Lines changed: 4 additions & 2 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 void ldisc_receive(struct tty_struct *tty, const u8 *data,
171-
char *flags, int count)
170+
static unsigned int ldisc_receive(struct tty_struct *tty,
171+
const u8 *data, char *flags, int count)
172172
{
173173
struct sk_buff *skb = NULL;
174174
struct ser_device *ser;
@@ -215,6 +215,8 @@ static void ldisc_receive(struct tty_struct *tty, const u8 *data,
215215
} else
216216
++ser->dev->stats.rx_dropped;
217217
update_tty_status(ser);
218+
219+
return count;
218220
}
219221

220222
static int handle_tx(struct ser_device *ser)

‎drivers/net/can/slcan.c‎

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

428-
static void slcan_receive_buf(struct tty_struct *tty,
428+
static unsigned int 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;
432433

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

436437
/* Read the characters out of the buffer */
437-
while (count--) {
438+
while (bytes--) {
438439
if (fp && *fp++) {
439440
if (!test_and_set_bit(SLF_ERROR, &sl->flags))
440441
sl->dev->stats.rx_errors++;
@@ -443,6 +444,8 @@ static void slcan_receive_buf(struct tty_struct *tty,
443444
}
444445
slcan_unesc(sl, *cp++);
445446
}
447+
448+
return count;
446449
}
447450

448451
/************************************

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

Lines changed: 5 additions & 3 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 void sixpack_receive_buf(struct tty_struct *tty,
459+
static unsigned int 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;
467+
return 0;
468468

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

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

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

488488
sp_put(sp);
489489
tty_unthrottle(tty);
490+
491+
return count1;
490492
}
491493

492494
/*

‎drivers/net/hamradio/mkiss.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -923,13 +923,14 @@ 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 void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp,
927-
char *fp, int count)
926+
static unsigned int mkiss_receive_buf(struct tty_struct *tty,
927+
const unsigned char *cp, char *fp, int count)
928928
{
929929
struct mkiss *ax = mkiss_get(tty);
930+
int bytes = count;
930931

931932
if (!ax)
932-
return;
933+
return -ENODEV;
933934

934935
/*
935936
* Argh! mtu change time! - costs us the packet part received
@@ -939,7 +940,7 @@ static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp,
939940
ax_changedmtu(ax);
940941

941942
/* Read the characters out of the buffer */
942-
while (count--) {
943+
while (bytes--) {
943944
if (fp != NULL && *fp++) {
944945
if (!test_and_set_bit(AXF_ERROR, &ax->flags))
945946
ax->dev->stats.rx_errors++;
@@ -952,6 +953,8 @@ static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp,
952953

953954
mkiss_put(ax);
954955
tty_unthrottle(tty);
956+
957+
return count;
955958
}
956959

957960
/*

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

Lines changed: 9 additions & 7 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 void irtty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
220-
char *fp, int count)
219+
static unsigned int irtty_receive_buf(struct tty_struct *tty,
220+
const unsigned char *cp, 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;);
227-
IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return;);
226+
IRDA_ASSERT(priv != NULL, return -ENODEV;);
227+
IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -EINVAL;);
228228

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

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

238238
for (i = 0; i < count; i++) {
@@ -242,11 +242,13 @@ static void irtty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
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;
245+
return -EINVAL;
246246
}
247247
}
248248

249249
sirdev_receive(dev, cp, count);
250+
251+
return count;
250252
}
251253

252254
/*

‎drivers/net/ppp_async.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,22 +340,24 @@ 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 void
343+
static unsigned int
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;
351+
return -ENODEV;
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;
359361
}
360362

361363
static void

0 commit comments

Comments
 (0)