From: Marek Vasut Date: Sun, 16 Apr 2017 18:11:46 +0200 Subject: [U-Boot] [PATCH 1/1] usbtty: avoid potential NULL pointer dereference In-Reply-To: <20170415130546.25341-1-xypron.glpk@gmx.de> References: <20170415130546.25341-1-xypron.glpk@gmx.de> Message-ID: <64eb9409-afd3-750a-e364-911a2ea43606@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 04/15/2017 03:05 PM, Heinrich Schuchardt wrote: > If current_urb is NULL it should not be dereferenced. > > The problem was indicated by cppcheck. > > Signed-off-by: Heinrich Schuchardt Applied, thanks. > --- > drivers/serial/usbtty.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c > index 2e19813643..29799dce93 100644 > --- a/drivers/serial/usbtty.c > +++ b/drivers/serial/usbtty.c > @@ -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; > > -- Best regards, Marek Vasut