diff mbox series

[5/5] usb: gadget: u_serial: diagnose missed console messages

Message ID 78e9b2c9313dea8a35f5b6f2a2c285c5f2f5ecbb.1551253561.git.mirq-linux@rere.qmqm.pl (mailing list archive)
State Superseded
Headers show
Series usb: gadget: u_serial: console for multiple ports | expand

Commit Message

Michał Mirosław Feb. 27, 2019, 7:48 a.m. UTC
Insert markers in console stream instead of making console output
glued together when drops happen.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/usb/gadget/function/u_serial.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Greg KH Feb. 27, 2019, 8:47 a.m. UTC | #1
On Wed, Feb 27, 2019 at 08:48:58AM +0100, Michał Mirosław wrote:
> Insert markers in console stream instead of making console output
> glued together when drops happen.

I'm sorry, but I can not understand this sentance at all.  Can you
please write more here to help out?

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 7b719c166517..f025cb958362 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -88,6 +88,7 @@  struct gs_console {
 	spinlock_t		lock;
 	struct usb_request	*req;
 	struct kfifo		buf;
+	size_t			missed;
 };
 
 /*
@@ -930,6 +931,15 @@  static void __gs_console_push(struct gs_console *cons)
 	if (!size)
 		return;
 
+	if (cons->missed && ep->maxpacket >= 64) {
+		char buf[64];
+		size_t len;
+
+		len = sprintf(buf, "\n[MISSED %zu bytes]\n", cons->missed);
+		kfifo_in(&cons->buf, buf, len);
+		cons->missed = 0;
+	}
+
 	req->length = size;
 	if (usb_ep_queue(ep, req, GFP_ATOMIC))
 		req->length = 0;
@@ -951,10 +961,13 @@  static void gs_console_write(struct console *co,
 {
 	struct gs_console *cons = container_of(co, struct gs_console, console);
 	unsigned long flags;
+	size_t n;
 
 	spin_lock_irqsave(&cons->lock, flags);
 
-	kfifo_in(&cons->buf, buf, count);
+	n = kfifo_in(&cons->buf, buf, count);
+	if (n < count)
+		cons->missed += count - n;
 
 	if (cons->req && !cons->req->length)
 		schedule_work(&cons->work);