]> git.sur5r.net Git - u-boot/blobdiff - drivers/serial/usbtty.c
Merge branch 'master' of git://git.denx.de/u-boot-socfpga
[u-boot] / drivers / serial / usbtty.c
index 75f0ec31bbfb9a6faedeaf9cf137ea1212ceefd5..d0465b844ed975e41336c46c91e9306dc9665f7b 100644 (file)
@@ -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 <common.h>
@@ -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 ();
@@ -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,12 +876,6 @@ 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;