Commit b1c43f82 authored by Felipe Balbi's avatar Felipe Balbi Committed by Greg Kroah-Hartman

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: default avatarStefan Bigler <stefan.bigler@keymile.com>
Tested-by: default avatarToby Gray <toby.gray@realvnc.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent e9a470f4
...@@ -357,22 +357,26 @@ static void hci_uart_tty_wakeup(struct tty_struct *tty) ...@@ -357,22 +357,26 @@ static void hci_uart_tty_wakeup(struct tty_struct *tty)
* *
* Return Value: None * Return Value: None
*/ */
static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data, char *flags, int count) static unsigned int hci_uart_tty_receive(struct tty_struct *tty,
const u8 *data, char *flags, int count)
{ {
struct hci_uart *hu = (void *)tty->disc_data; struct hci_uart *hu = (void *)tty->disc_data;
int received;
if (!hu || tty != hu->tty) if (!hu || tty != hu->tty)
return; return -ENODEV;
if (!test_bit(HCI_UART_PROTO_SET, &hu->flags)) if (!test_bit(HCI_UART_PROTO_SET, &hu->flags))
return; return -EINVAL;
spin_lock(&hu->rx_lock); spin_lock(&hu->rx_lock);
hu->proto->recv(hu, (void *) data, count); received = hu->proto->recv(hu, (void *) data, count);
hu->hdev->stat.byte_rx += count; hu->hdev->stat.byte_rx += count;
spin_unlock(&hu->rx_lock); spin_unlock(&hu->rx_lock);
tty_unthrottle(tty); tty_unthrottle(tty);
return received;
} }
static int hci_uart_register_dev(struct hci_uart *hu) static int hci_uart_register_dev(struct hci_uart *hu)
......
...@@ -120,17 +120,21 @@ static void serport_ldisc_close(struct tty_struct *tty) ...@@ -120,17 +120,21 @@ static void serport_ldisc_close(struct tty_struct *tty)
* 'interrupt' routine. * 'interrupt' routine.
*/ */
static void serport_ldisc_receive(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) static unsigned int serport_ldisc_receive(struct tty_struct *tty,
const unsigned char *cp, char *fp, int count)
{ {
struct serport *serport = (struct serport*) tty->disc_data; struct serport *serport = (struct serport*) tty->disc_data;
unsigned long flags; unsigned long flags;
unsigned int ch_flags; unsigned int ch_flags;
int ret = 0;
int i; int i;
spin_lock_irqsave(&serport->lock, flags); spin_lock_irqsave(&serport->lock, flags);
if (!test_bit(SERPORT_ACTIVE, &serport->flags)) if (!test_bit(SERPORT_ACTIVE, &serport->flags)) {
ret = -EINVAL;
goto out; goto out;
}
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
switch (fp[i]) { switch (fp[i]) {
...@@ -152,6 +156,8 @@ static void serport_ldisc_receive(struct tty_struct *tty, const unsigned char *c ...@@ -152,6 +156,8 @@ static void serport_ldisc_receive(struct tty_struct *tty, const unsigned char *c
out: out:
spin_unlock_irqrestore(&serport->lock, flags); spin_unlock_irqrestore(&serport->lock, flags);
return ret == 0 ? count : ret;
} }
/* /*
......
...@@ -674,7 +674,7 @@ gigaset_tty_ioctl(struct tty_struct *tty, struct file *file, ...@@ -674,7 +674,7 @@ gigaset_tty_ioctl(struct tty_struct *tty, struct file *file,
* cflags buffer containing error flags for received characters (ignored) * cflags buffer containing error flags for received characters (ignored)
* count number of received characters * count number of received characters
*/ */
static void static unsigned int
gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf, gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf,
char *cflags, int count) char *cflags, int count)
{ {
...@@ -683,12 +683,12 @@ gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf, ...@@ -683,12 +683,12 @@ gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf,
struct inbuf_t *inbuf; struct inbuf_t *inbuf;
if (!cs) if (!cs)
return; return -ENODEV;
inbuf = cs->inbuf; inbuf = cs->inbuf;
if (!inbuf) { if (!inbuf) {
dev_err(cs->dev, "%s: no inbuf\n", __func__); dev_err(cs->dev, "%s: no inbuf\n", __func__);
cs_put(cs); cs_put(cs);
return; return -EINVAL;
} }
tail = inbuf->tail; tail = inbuf->tail;
...@@ -725,6 +725,8 @@ gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf, ...@@ -725,6 +725,8 @@ gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf,
gig_dbg(DEBUG_INTR, "%s-->BH", __func__); gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
gigaset_schedule_event(cs); gigaset_schedule_event(cs);
cs_put(cs); cs_put(cs);
return count;
} }
/* /*
......
...@@ -744,8 +744,8 @@ static void st_tty_close(struct tty_struct *tty) ...@@ -744,8 +744,8 @@ static void st_tty_close(struct tty_struct *tty)
pr_debug("%s: done ", __func__); pr_debug("%s: done ", __func__);
} }
static void st_tty_receive(struct tty_struct *tty, const unsigned char *data, static unsigned int st_tty_receive(struct tty_struct *tty,
char *tty_flags, int count) const unsigned char *data, char *tty_flags, int count)
{ {
#ifdef VERBOSE #ifdef VERBOSE
print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE, 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, ...@@ -758,6 +758,8 @@ static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
*/ */
st_recv(tty->disc_data, data, count); st_recv(tty->disc_data, data, count);
pr_debug("done %s", __func__); pr_debug("done %s", __func__);
return count;
} }
/* wake-up function called in from the TTY layer /* wake-up function called in from the TTY layer
......
...@@ -167,8 +167,8 @@ static inline void debugfs_tx(struct ser_device *ser, const u8 *data, int size) ...@@ -167,8 +167,8 @@ static inline void debugfs_tx(struct ser_device *ser, const u8 *data, int size)
#endif #endif
static void ldisc_receive(struct tty_struct *tty, const u8 *data, static unsigned int ldisc_receive(struct tty_struct *tty,
char *flags, int count) const u8 *data, char *flags, int count)
{ {
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
struct ser_device *ser; struct ser_device *ser;
...@@ -215,6 +215,8 @@ static void ldisc_receive(struct tty_struct *tty, const u8 *data, ...@@ -215,6 +215,8 @@ static void ldisc_receive(struct tty_struct *tty, const u8 *data,
} else } else
++ser->dev->stats.rx_dropped; ++ser->dev->stats.rx_dropped;
update_tty_status(ser); update_tty_status(ser);
return count;
} }
static int handle_tx(struct ser_device *ser) static int handle_tx(struct ser_device *ser)
......
...@@ -425,16 +425,17 @@ static void slc_setup(struct net_device *dev) ...@@ -425,16 +425,17 @@ static void slc_setup(struct net_device *dev)
* in parallel * in parallel
*/ */
static void slcan_receive_buf(struct tty_struct *tty, static unsigned int slcan_receive_buf(struct tty_struct *tty,
const unsigned char *cp, char *fp, int count) const unsigned char *cp, char *fp, int count)
{ {
struct slcan *sl = (struct slcan *) tty->disc_data; struct slcan *sl = (struct slcan *) tty->disc_data;
int bytes = count;
if (!sl || sl->magic != SLCAN_MAGIC || !netif_running(sl->dev)) if (!sl || sl->magic != SLCAN_MAGIC || !netif_running(sl->dev))
return; return -ENODEV;
/* Read the characters out of the buffer */ /* Read the characters out of the buffer */
while (count--) { while (bytes--) {
if (fp && *fp++) { if (fp && *fp++) {
if (!test_and_set_bit(SLF_ERROR, &sl->flags)) if (!test_and_set_bit(SLF_ERROR, &sl->flags))
sl->dev->stats.rx_errors++; sl->dev->stats.rx_errors++;
...@@ -443,6 +444,8 @@ static void slcan_receive_buf(struct tty_struct *tty, ...@@ -443,6 +444,8 @@ static void slcan_receive_buf(struct tty_struct *tty,
} }
slcan_unesc(sl, *cp++); slcan_unesc(sl, *cp++);
} }
return count;
} }
/************************************ /************************************
......
...@@ -456,7 +456,7 @@ out: ...@@ -456,7 +456,7 @@ out:
* a block of 6pack data has been received, which can now be decapsulated * a block of 6pack data has been received, which can now be decapsulated
* and sent on to some IP layer for further processing. * and sent on to some IP layer for further processing.
*/ */
static void sixpack_receive_buf(struct tty_struct *tty, static unsigned int sixpack_receive_buf(struct tty_struct *tty,
const unsigned char *cp, char *fp, int count) const unsigned char *cp, char *fp, int count)
{ {
struct sixpack *sp; struct sixpack *sp;
...@@ -464,11 +464,11 @@ static void sixpack_receive_buf(struct tty_struct *tty, ...@@ -464,11 +464,11 @@ static void sixpack_receive_buf(struct tty_struct *tty,
int count1; int count1;
if (!count) if (!count)
return; return 0;
sp = sp_get(tty); sp = sp_get(tty);
if (!sp) if (!sp)
return; return -ENODEV;
memcpy(buf, cp, count < sizeof(buf) ? count : sizeof(buf)); memcpy(buf, cp, count < sizeof(buf) ? count : sizeof(buf));
...@@ -487,6 +487,8 @@ static void sixpack_receive_buf(struct tty_struct *tty, ...@@ -487,6 +487,8 @@ static void sixpack_receive_buf(struct tty_struct *tty,
sp_put(sp); sp_put(sp);
tty_unthrottle(tty); tty_unthrottle(tty);
return count1;
} }
/* /*
......
...@@ -923,13 +923,14 @@ static long mkiss_compat_ioctl(struct tty_struct *tty, struct file *file, ...@@ -923,13 +923,14 @@ static long mkiss_compat_ioctl(struct tty_struct *tty, struct file *file,
* a block of data has been received, which can now be decapsulated * a block of data has been received, which can now be decapsulated
* and sent on to the AX.25 layer for further processing. * and sent on to the AX.25 layer for further processing.
*/ */
static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp, static unsigned int mkiss_receive_buf(struct tty_struct *tty,
char *fp, int count) const unsigned char *cp, char *fp, int count)
{ {
struct mkiss *ax = mkiss_get(tty); struct mkiss *ax = mkiss_get(tty);
int bytes = count;
if (!ax) if (!ax)
return; return -ENODEV;
/* /*
* Argh! mtu change time! - costs us the packet part received * 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, ...@@ -939,7 +940,7 @@ static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp,
ax_changedmtu(ax); ax_changedmtu(ax);
/* Read the characters out of the buffer */ /* Read the characters out of the buffer */
while (count--) { while (bytes--) {
if (fp != NULL && *fp++) { if (fp != NULL && *fp++) {
if (!test_and_set_bit(AXF_ERROR, &ax->flags)) if (!test_and_set_bit(AXF_ERROR, &ax->flags))
ax->dev->stats.rx_errors++; ax->dev->stats.rx_errors++;
...@@ -952,6 +953,8 @@ static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp, ...@@ -952,6 +953,8 @@ static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp,
mkiss_put(ax); mkiss_put(ax);
tty_unthrottle(tty); tty_unthrottle(tty);
return count;
} }
/* /*
......
...@@ -216,23 +216,23 @@ static int irtty_do_write(struct sir_dev *dev, const unsigned char *ptr, size_t ...@@ -216,23 +216,23 @@ static int irtty_do_write(struct sir_dev *dev, const unsigned char *ptr, size_t
* usbserial: urb-complete-interrupt / softint * usbserial: urb-complete-interrupt / softint
*/ */
static void irtty_receive_buf(struct tty_struct *tty, const unsigned char *cp, static unsigned int irtty_receive_buf(struct tty_struct *tty,
char *fp, int count) const unsigned char *cp, char *fp, int count)
{ {
struct sir_dev *dev; struct sir_dev *dev;
struct sirtty_cb *priv = tty->disc_data; struct sirtty_cb *priv = tty->disc_data;
int i; int i;
IRDA_ASSERT(priv != NULL, return;); IRDA_ASSERT(priv != NULL, return -ENODEV;);
IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return;); IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -EINVAL;);
if (unlikely(count==0)) /* yes, this happens */ if (unlikely(count==0)) /* yes, this happens */
return; return 0;
dev = priv->dev; dev = priv->dev;
if (!dev) { if (!dev) {
IRDA_WARNING("%s(), not ready yet!\n", __func__); IRDA_WARNING("%s(), not ready yet!\n", __func__);
return; return -ENODEV;
} }
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
...@@ -242,11 +242,13 @@ static void irtty_receive_buf(struct tty_struct *tty, const unsigned char *cp, ...@@ -242,11 +242,13 @@ static void irtty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
if (fp && *fp++) { if (fp && *fp++) {
IRDA_DEBUG(0, "Framing or parity error!\n"); IRDA_DEBUG(0, "Framing or parity error!\n");
sirdev_receive(dev, NULL, 0); /* notify sir_dev (updating stats) */ sirdev_receive(dev, NULL, 0); /* notify sir_dev (updating stats) */
return; return -EINVAL;
} }
} }
sirdev_receive(dev, cp, count); sirdev_receive(dev, cp, count);
return count;
} }
/* /*
......
...@@ -340,7 +340,7 @@ ppp_asynctty_poll(struct tty_struct *tty, struct file *file, poll_table *wait) ...@@ -340,7 +340,7 @@ ppp_asynctty_poll(struct tty_struct *tty, struct file *file, poll_table *wait)
} }
/* May sleep, don't call from interrupt level or with interrupts disabled */ /* May sleep, don't call from interrupt level or with interrupts disabled */
static void static unsigned int
ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf, ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf,
char *cflags, int count) char *cflags, int count)
{ {
...@@ -348,7 +348,7 @@ ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf, ...@@ -348,7 +348,7 @@ ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf,
unsigned long flags; unsigned long flags;
if (!ap) if (!ap)
return; return -ENODEV;
spin_lock_irqsave(&ap->recv_lock, flags); spin_lock_irqsave(&ap->recv_lock, flags);
ppp_async_input(ap, buf, cflags, count); ppp_async_input(ap, buf, cflags, count);
spin_unlock_irqrestore(&ap->recv_lock, flags); spin_unlock_irqrestore(&ap->recv_lock, flags);
...@@ -356,6 +356,8 @@ ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf, ...@@ -356,6 +356,8 @@ ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf,
tasklet_schedule(&ap->tsk); tasklet_schedule(&ap->tsk);
ap_put(ap); ap_put(ap);
tty_unthrottle(tty); tty_unthrottle(tty);
return count;
} }
static void static void
......
...@@ -381,7 +381,7 @@ ppp_sync_poll(struct tty_struct *tty, struct file *file, poll_table *wait) ...@@ -381,7 +381,7 @@ ppp_sync_poll(struct tty_struct *tty, struct file *file, poll_table *wait)
} }
/* May sleep, don't call from interrupt level or with interrupts disabled */ /* May sleep, don't call from interrupt level or with interrupts disabled */
static void static unsigned int
ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf, ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf,
char *cflags, int count) char *cflags, int count)
{ {
...@@ -389,7 +389,7 @@ ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf, ...@@ -389,7 +389,7 @@ ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf,
unsigned long flags; unsigned long flags;
if (!ap) if (!ap)
return; return -ENODEV;
spin_lock_irqsave(&ap->recv_lock, flags); spin_lock_irqsave(&ap->recv_lock, flags);
ppp_sync_input(ap, buf, cflags, count); ppp_sync_input(ap, buf, cflags, count);
spin_unlock_irqrestore(&ap->recv_lock, flags); spin_unlock_irqrestore(&ap->recv_lock, flags);
...@@ -397,6 +397,8 @@ ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf, ...@@ -397,6 +397,8 @@ ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf,
tasklet_schedule(&ap->tsk); tasklet_schedule(&ap->tsk);
sp_put(ap); sp_put(ap);
tty_unthrottle(tty); tty_unthrottle(tty);
return count;
} }
static void static void
......
...@@ -670,16 +670,17 @@ static void sl_setup(struct net_device *dev) ...@@ -670,16 +670,17 @@ static void sl_setup(struct net_device *dev)
* in parallel * in parallel
*/ */
static void slip_receive_buf(struct tty_struct *tty, const unsigned char *cp, static unsigned int slip_receive_buf(struct tty_struct *tty,
char *fp, int count) const unsigned char *cp, char *fp, int count)
{ {
struct slip *sl = tty->disc_data; struct slip *sl = tty->disc_data;
int bytes = count;
if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev)) if (!sl || sl->magic != SLIP_MAGIC || !netif_running(sl->dev))
return; return -ENODEV;
/* Read the characters out of the buffer */ /* Read the characters out of the buffer */
while (count--) { while (bytes--) {
if (fp && *fp++) { if (fp && *fp++) {
if (!test_and_set_bit(SLF_ERROR, &sl->flags)) if (!test_and_set_bit(SLF_ERROR, &sl->flags))
sl->dev->stats.rx_errors++; sl->dev->stats.rx_errors++;
...@@ -693,6 +694,8 @@ static void slip_receive_buf(struct tty_struct *tty, const unsigned char *cp, ...@@ -693,6 +694,8 @@ static void slip_receive_buf(struct tty_struct *tty, const unsigned char *cp,
#endif #endif
slip_unesc(sl, *cp++); slip_unesc(sl, *cp++);
} }
return count;
} }
/************************************ /************************************
......
...@@ -517,17 +517,18 @@ static int x25_asy_close(struct net_device *dev) ...@@ -517,17 +517,18 @@ static int x25_asy_close(struct net_device *dev)
* and sent on to some IP layer for further processing. * and sent on to some IP layer for further processing.
*/ */
static void x25_asy_receive_buf(struct tty_struct *tty, static unsigned int x25_asy_receive_buf(struct tty_struct *tty,
const unsigned char *cp, char *fp, int count) const unsigned char *cp, char *fp, int count)
{ {
struct x25_asy *sl = tty->disc_data; struct x25_asy *sl = tty->disc_data;
int bytes = count;
if (!sl || sl->magic != X25_ASY_MAGIC || !netif_running(sl->dev)) if (!sl || sl->magic != X25_ASY_MAGIC || !netif_running(sl->dev))
return; return;
/* Read the characters out of the buffer */ /* Read the characters out of the buffer */
while (count--) { while (bytes--) {
if (fp && *fp++) { if (fp && *fp++) {
if (!test_and_set_bit(SLF_ERROR, &sl->flags)) if (!test_and_set_bit(SLF_ERROR, &sl->flags))
sl->dev->stats.rx_errors++; sl->dev->stats.rx_errors++;
...@@ -536,6 +537,8 @@ static void x25_asy_receive_buf(struct tty_struct *tty, ...@@ -536,6 +537,8 @@ static void x25_asy_receive_buf(struct tty_struct *tty,
} }
x25_asy_unesc(sl, *cp++); x25_asy_unesc(sl, *cp++);
} }
return count;
} }
/* /*
......
...@@ -2138,8 +2138,8 @@ static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) ...@@ -2138,8 +2138,8 @@ static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
gsm->tty = NULL; gsm->tty = NULL;
} }
static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp, static unsigned int gsmld_receive_buf(struct tty_struct *tty,
char *fp, int count) const unsigned char *cp, char *fp, int count)
{ {
struct gsm_mux *gsm = tty->disc_data; struct gsm_mux *gsm = tty->disc_data;
const unsigned char *dp; const unsigned char *dp;
...@@ -2173,6 +2173,8 @@ static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp, ...@@ -2173,6 +2173,8 @@ static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
} }
/* FASYNC if needed ? */ /* FASYNC if needed ? */
/* If clogged call tty_throttle(tty); */ /* If clogged call tty_throttle(tty); */
return count;
} }
/** /**
......
...@@ -188,8 +188,8 @@ static unsigned int n_hdlc_tty_poll(struct tty_struct *tty, struct file *filp, ...@@ -188,8 +188,8 @@ static unsigned int n_hdlc_tty_poll(struct tty_struct *tty, struct file *filp,
poll_table *wait); poll_table *wait);
static int n_hdlc_tty_open(struct tty_struct *tty); static int n_hdlc_tty_open(struct tty_struct *tty);
static void n_hdlc_tty_close(struct tty_struct *tty); static void n_hdlc_tty_close(struct tty_struct *tty);
static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *cp,