Path: csiph.com!1.us.feeder.erje.net!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.datemas.de!enother.net!enother.net!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod From: Stas Sergeev Newsgroups: linux.kernel Subject: [PATCH] mos7840: fix chars_in_buffer() return value Date: Sat, 24 Sep 2016 15:50:01 +0200 Message-ID: X-Greylist: delayed 64986 seconds by postgrey-1.27 at vger.kernel.org; Sat, 24 Sep 2016 09:47:16 EDT Dkim-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=list.ru; s=mail; h=Message-Id:Date:Subject:Cc:To:From; bh=bj1l5dYQI5vSsesIlpv/FXcETI0yUKrA1NlxFW2iXKM=; b=K6TLH/CTny6fTJvwUvIG+KJxdoxMBZ12B6NqJbLRg9JMHKv9Hh75Qw5kg/TfYDCuy8lh4qyucbbxUiMPh9o7QZ4ZMdIIHg5cYjqITYunRqsFrLGnmaq8t/uBNY/X5xrU/9Vo41c0YapmvGv2ZCFcrnEANajOTe1E+hdEpSEEMmg=; X-Mailer: git-send-email 2.7.4 Authentication-Results: smtp48.i.mail.ru; auth=pass smtp.auth=stsp@list.ru smtp.mailfrom=stsp@list.ru X-Mailru-Sender: 93A3050EDC2B741E47B042B830B848C585E9763D5D4F3028BB773D5342625CD2C885194977843C77224C9A2F61B97637 X-Mras: OK Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 67 Organization: linux.* mail to news gateway X-Original-Cc: Caylan Van Larson , Alan Cox , Johan Hovold , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org X-Original-Date: Sat, 24 Sep 2016 16:47:03 +0300 X-Original-Message-ID: <1474724823-28872-1-git-send-email-stsp@list.ru> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1490647 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 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 Reported-by: Caylan Van Larson CC: Caylan Van Larson CC: Alan Cox CC: Johan Hovold CC: Greg Kroah-Hartman 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