usbtty: avoid potential NULL pointer dereference
authorxypron.glpk@gmx.de <xypron.glpk@gmx.de>
Sat, 15 Apr 2017 13:05:46 +0000 (15:05 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 18 Apr 2017 14:29:23 +0000 (10:29 -0400)
If current_urb is NULL it should not be dereferenced.

The problem was indicated by cppcheck.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>
drivers/serial/usbtty.c

index 2e19813643bb093aa82f237db83627f7f028de1d..29799dce93a00fa1a547118fc16d493ad4323da7 100644 (file)
@@ -850,6 +850,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){
@@ -871,12 +878,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;