You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/08/29 17:41:33 UTC
[incubator-nuttx] branch master updated: risc-v/mpfs: usb: fix cppcheck findings
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 3665180795 risc-v/mpfs: usb: fix cppcheck findings
3665180795 is described below
commit 36651807955cd248d7e4ee6f7099cdd5a17ed435
Author: Eero Nurkkala <ee...@offcode.fi>
AuthorDate: Mon Aug 29 15:55:27 2022 +0300
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 <ee...@offcode.fi>
---
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;
}