mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stas Sergeev <stsp@list.ru>
To: stsp@list.ru
Cc: Caylan Van Larson <i@caylan.net>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Johan Hovold <johan@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mos7840: fix chars_in_buffer() return value
Date: Sat, 24 Sep 2016 16:47:03 +0300	[thread overview]
Message-ID: <1474724823-28872-1-git-send-email-stsp@list.ru> (raw)

The TIOCOUTQ ioctl calls chars_in_buffer(), and some apps depend on
a correct behaviour of that.
mos7840 implements it wrongly: if you write just one char, TIOCOUTQ
will return 32.
This patch should fix it by accounting the number of chars actually
writCaylan Van Larson <i@caylan.net>ten.
This patch, unfortunately, misses the Tesed-by tag.
The reported didn't test it, and I don't have the hardware in question.

Signed-off-by: Stas Sergeev <stsp@list.ru>
Reported-by: Caylan Van Larson <i@caylan.net>
CC: Caylan Van Larson <i@caylan.net>
CC: Alan Cox <alan@lxorguk.ukuu.org.uk>
CC: Johan Hovold <johan@kernel.org>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: linux-usb@vger.kernel.org
CC: linux-kernel@vger.kernel.org
---
 drivers/usb/serial/mos7840.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index ed378fb..2a1eb07 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -234,7 +234,7 @@ struct moschip_port {
 
 	spinlock_t pool_lock;
 	struct urb *write_urb_pool[NUM_URBS];
-	char busy[NUM_URBS];
+	int busy[NUM_URBS];
 	bool read_urb_busy;
 
 	/* For device(s) with LED indicator */
@@ -1139,8 +1139,7 @@ static int mos7840_chars_in_buffer(struct tty_struct *tty)
 	spin_lock_irqsave(&mos7840_port->pool_lock, flags);
 	for (i = 0; i < NUM_URBS; ++i) {
 		if (mos7840_port->busy[i]) {
-			struct urb *urb = mos7840_port->write_urb_pool[i];
-			chars += urb->transfer_buffer_length;
+			chars += mos7840_port->busy[i];
 		}
 	}
 	spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
@@ -1323,10 +1322,11 @@ static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
 	/* try to find a free urb in the list */
 	urb = NULL;
 
+	transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
 	spin_lock_irqsave(&mos7840_port->pool_lock, flags);
 	for (i = 0; i < NUM_URBS; ++i) {
 		if (!mos7840_port->busy[i]) {
-			mos7840_port->busy[i] = 1;
+			mos7840_port->busy[i] = transfer_size;
 			urb = mos7840_port->write_urb_pool[i];
 			dev_dbg(&port->dev, "URB:%d\n", i);
 			break;
@@ -1345,7 +1345,6 @@ static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
 		if (!urb->transfer_buffer)
 			goto exit;
 	}
-	transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
 
 	memcpy(urb->transfer_buffer, current_position, transfer_size);
 
-- 
2.7.4

             reply	other threads:[~2016-09-24 13:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-24 13:47 Stas Sergeev [this message]
2016-09-24 13:57 ` Sergei Shtylyov
2016-09-24 15:00   ` Stas Sergeev
2016-09-24 13:48 Stas Sergeev
2016-09-24 15:00 Stas Sergeev
2016-09-29 10:09 ` Johan Hovold
2016-09-29 21:00   ` Stas Sergeev
2016-09-30 11:04     ` Johan Hovold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1474724823-28872-1-git-send-email-stsp@list.ru \
    --to=stsp@list.ru \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=i@caylan.net \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome