linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: trix@redhat.com
To: balbi@kernel.org, gregkh@linuxfoundation.org,
	natechancellor@gmail.com, ndesaulniers@google.com,
	christophe.jaillet@wanadoo.fr, peter.chen@nxp.com, b-liu@ti.com,
	chunfeng.yun@mediatek.com, novikov@ispras.ru,
	yanaijie@huawei.com
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Tom Rix <trix@redhat.com>
Subject: [PATCH] usb: gadget: net2272: assert for a valid dma request
Date: Sun, 30 Aug 2020 11:36:46 -0700	[thread overview]
Message-ID: <20200830183646.24930-1-trix@redhat.com> (raw)

From: Tom Rix <trix@redhat.com>

clang static analysis flags this representive problem

net2272.c:1541:8: warning: Dereference of null pointer
    if ((req->req.length % ep->ep.maxpacket != 0) ||
         ^~~~~~~~~~~~~~~
This is mostly not a problem.

In net2272_handle_dma(), even though every path through
the routine dereferences req, it is set to NULL when the
ep->queue is empty.  If the eq->queue was ever empty this
would have oops.

So the else statement should not be needed.  If it is,
flag it as a BUG.

Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/usb/gadget/udc/net2272.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/udc/net2272.c b/drivers/usb/gadget/udc/net2272.c
index 44d1ea2307bb..8301723a8b1a 100644
--- a/drivers/usb/gadget/udc/net2272.c
+++ b/drivers/usb/gadget/udc/net2272.c
@@ -1506,17 +1506,16 @@ static int net2272_stop(struct usb_gadget *_gadget)
 static void
 net2272_handle_dma(struct net2272_ep *ep)
 {
-	struct net2272_request *req;
+	struct net2272_request *req = NULL;
 	unsigned len;
 	int status;
 
 	if (!list_empty(&ep->queue))
 		req = list_entry(ep->queue.next,
 				struct net2272_request, queue);
-	else
-		req = NULL;
 
 	dev_vdbg(ep->dev->dev, "handle_dma %s req %p\n", ep->ep.name, req);
+	BUG_ON(!req);
 
 	/* Ensure DREQ is de-asserted */
 	net2272_write(ep->dev, DMAREQ,
-- 
2.18.1


             reply	other threads:[~2020-08-30 18:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-30 18:36 trix [this message]
2020-08-30 21:22 ` [PATCH] usb: gadget: net2272: assert for a valid dma request Alan Stern
2020-08-30 21:35   ` Tom Rix
2020-08-31  5:31 ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200830183646.24930-1-trix@redhat.com \
    --to=trix@redhat.com \
    --cc=b-liu@ti.com \
    --cc=balbi@kernel.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=chunfeng.yun@mediatek.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=natechancellor@gmail.com \
    --cc=ndesaulniers@google.com \
    --cc=novikov@ispras.ru \
    --cc=peter.chen@nxp.com \
    --cc=yanaijie@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).