X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fserial%2Fusbtty.c;h=d0465b844ed975e41336c46c91e9306dc9665f7b;hb=ee1855dc52fc366f33e21182103323c236cb3346;hp=b030526b6a1f51f182b1fd6a7558c641b5f0b32a;hpb=302e609fe653baf1ae3a7573d2f4eafd86ab696b;p=u-boot diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c index b030526b6a..d0465b844e 100644 --- a/drivers/serial/usbtty.c +++ b/drivers/serial/usbtty.c @@ -1,11 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2003 * Gerry Hamel, geh@ti.com, Texas Instruments * * (C) Copyright 2006 * Bryan O'Donoghue, bodonoghue@codehermit.ie - * - * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -434,11 +433,12 @@ void usbtty_putc(struct stdio_dev *dev, const char c) if (!usbtty_configured ()) return; - buf_push (&usbtty_output, &c, 1); /* If \n, also do \r */ if (c == '\n') buf_push (&usbtty_output, "\r", 1); + buf_push(&usbtty_output, &c, 1); + /* Poll at end to handle new data... */ if ((usbtty_output.size + 2) >= usbtty_output.totalsize) { usbtty_poll (); @@ -475,7 +475,7 @@ static void __usbtty_puts (const char *str, int len) if (space) { write_buffer (&usbtty_output); - n = MIN (space, MIN (len, maxlen)); + n = min(space, min(len, maxlen)); buf_push (&usbtty_output, str, n); str += n; @@ -498,8 +498,8 @@ void usbtty_puts(struct stdio_dev *dev, const char *str) n = next_nl_pos (str); if (str[n] == '\n') { - __usbtty_puts (str, n + 1); - __usbtty_puts ("\r", 1); + __usbtty_puts("\r", 1); + __usbtty_puts(str, n + 1); str += (n + 1); len -= (n + 1); } else { @@ -524,10 +524,10 @@ int drv_usbtty_init (void) char * tt; int snlen; - /* Ger seiral number */ - if (!(sn = getenv("serial#"))) { + /* Get serial number */ + sn = env_get("serial#"); + if (!sn) sn = "000000000000"; - } snlen = strlen(sn); if (snlen > sizeof(serial_number) - 1) { printf ("Warning: serial number %s is too long (%d > %lu)\n", @@ -539,10 +539,9 @@ int drv_usbtty_init (void) /* Decide on which type of UDC device to be. */ - - if(!(tt = getenv("usbtty"))) { + tt = env_get("usbtty"); + if (!tt) tt = "generic"; - } usbtty_init_terminal_type(strcmp(tt,"cdc_acm")); /* prepare buffers... */ @@ -849,6 +848,13 @@ static int write_buffer (circbuf_t * buf) 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){ @@ -870,19 +876,13 @@ static int write_buffer (circbuf_t * buf) */ while (buf->size > 0) { - if (!current_urb) { - TTYERR ("current_urb is NULL, buf->size %d\n", - buf->size); - return total; - } - dest = (char*)current_urb->buffer + current_urb->actual_length; space_avail = current_urb->buffer_length - current_urb->actual_length; - popnum = MIN (space_avail, buf->size); + popnum = min(space_avail, (int)buf->size); if (popnum == 0) break;