serial: usbtty: Send urb data in correct order

Function next_urb() selects the last urb data buffer from linked list to
which next data from usbtty's puts function should be appended.

But to check if TX data still exists it is needed to look at the first urb
data buffer from linked list. So check for endpoint->tx_urb (first from the
linked list) instead of current_urb (the last from the linked list).

Successful call to udc_endpoint_write() may invalidate active urb and
allocate new urb in queue which invalidates pointer returned by next_urb()
function.

So call next_urb() prior putting data into urb buffer and call it every
time after using udc_endpoint_write() function to prevent sending data from
usbtty's puts function in incorrect order.

This patch fixes issue that usbtty code does not transmit data when they
are waiting in the tx queue.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
Acked-by: Pavel Machek <pavel@ucw.cz>
This commit is contained in:
Pali Rohár 2021-02-07 14:50:02 +01:00 committed by Marek Vasut
parent d3fb8fee7d
commit 7f840c1b26
1 changed files with 3 additions and 9 deletions

View File

@ -849,17 +849,9 @@ static int write_buffer (circbuf_t * buf)
&endpoint_instance[tx_endpoint];
struct urb *current_urb = NULL;
current_urb = next_urb (device_instance, endpoint);
if (!current_urb) {
TTYERR ("current_urb is NULL, buf->size %d\n",
buf->size);
return 0;
}
/* TX data still exists - send it now
*/
if(endpoint->sent < current_urb->actual_length){
if(endpoint->sent < endpoint->tx_urb->actual_length){
if(udc_endpoint_write (endpoint)){
/* Write pre-empted by RX */
return -1;
@ -878,6 +870,8 @@ static int write_buffer (circbuf_t * buf)
*/
while (buf->size > 0) {
current_urb = next_urb (device_instance, endpoint);
dest = (char*)current_urb->buffer +
current_urb->actual_length;