From 36651807955cd248d7e4ee6f7099cdd5a17ed435 Mon Sep 17 00:00:00 2001 From: Eero Nurkkala Date: Mon, 29 Aug 2022 15:55:27 +0300 Subject: [PATCH] risc-v/mpfs: usb: fix cppcheck findings Fix the following cppcheck findings. Privreq may be NULL, thus perform checks before using its member variables. Checking mpfs_usb.c ... mpfs_usb.c:1093:12: warning: Possible null pointer dereference: privreq [nullPointer] if ((privreq->inflight > 0) && (count != 0) && ^ mpfs_usb.c:1090:21: note: Assignment 'privreq=NULL', assigned value is 0 privreq = NULL; ^ mpfs_usb.c:1093:12: note: Null pointer dereference if ((privreq->inflight > 0) && (count != 0) && ^ mpfs_usb.c:1138:3: warning: Possible null pointer dereference: privreq [nullPointer] privreq->req.xfrd = 0; ^ mpfs_usb.c:1130:21: note: Assignment 'privreq=NULL', assigned value is 0 privreq = NULL; ^ mpfs_usb.c:1138:3: note: Null pointer dereference privreq->req.xfrd = 0; ^ mpfs_usb.c:1139:3: warning: Possible null pointer dereference: privreq [nullPointer] privreq->inflight = privreq->req.len; ^ mpfs_usb.c:1130:21: note: Assignment 'privreq=NULL', assigned value is 0 privreq = NULL; ^ mpfs_usb.c:1139:3: note: Null pointer dereference privreq->inflight = privreq->req.len; ^ mpfs_usb.c:1140:50: warning: Possible null pointer dereference: privreq [nullPointer] priv->eplist[epno].descb[0]->addr = (uintptr_t)privreq->req.buf; ^ mpfs_usb.c:1130:21: note: Assignment 'privreq=NULL', assigned value is 0 privreq = NULL; ^ mpfs_usb.c:1140:50: note: Null pointer dereference priv->eplist[epno].descb[0]->addr = (uintptr_t)privreq->req.buf; Signed-off-by: Eero Nurkkala --- arch/risc-v/src/mpfs/mpfs_usb.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/risc-v/src/mpfs/mpfs_usb.c b/arch/risc-v/src/mpfs/mpfs_usb.c index ee317a2f0a..e29b8b1043 100644 --- a/arch/risc-v/src/mpfs/mpfs_usb.c +++ b/arch/risc-v/src/mpfs/mpfs_usb.c @@ -1090,7 +1090,7 @@ static int mpfs_req_read(struct mpfs_usbdev_s *priv, privreq = NULL; } - if ((privreq->inflight > 0) && (count != 0) && + if ((privreq != NULL) && (privreq->inflight > 0) && (count != 0) && (reg & RXCSRL_REG_EPN_RX_PKT_RDY_MASK) != 0) { /* Update the total number of bytes transferred */ @@ -1135,9 +1135,12 @@ static int mpfs_req_read(struct mpfs_usbdev_s *priv, /* Activate new read request from queue */ privep->rxactive = true; - privreq->req.xfrd = 0; - privreq->inflight = privreq->req.len; - priv->eplist[epno].descb[0]->addr = (uintptr_t)privreq->req.buf; + if (privreq != NULL) + { + privreq->req.xfrd = 0; + privreq->inflight = privreq->req.len; + priv->eplist[epno].descb[0]->addr = (uintptr_t)privreq->req.buf; + } return OK; }