2019-11-10 22:15:30

by Colin King

[permalink] [raw]
Subject: [PATCH] usb: gadget: udc: lpc32xx: don't dereference ep until it has been null checked

From: Colin Ian King <[email protected]>

The pointer ep is currently being dereferenced when initializing pointer
udc before ep is being null checked. Fix this by only dereferencing
ep after it has been null checked.

Addresses-Coverity: ("Dereference before null check")
Fixes: 24a28e428351 ("USB: gadget driver for LPC32xx")
Signed-off-by: Colin Ian King <[email protected]>
---
drivers/usb/gadget/udc/lpc32xx_udc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c
index d14b2bb3f67c..45b2a673ecba 100644
--- a/drivers/usb/gadget/udc/lpc32xx_udc.c
+++ b/drivers/usb/gadget/udc/lpc32xx_udc.c
@@ -1872,7 +1872,7 @@ static int lpc32xx_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
static int lpc32xx_ep_set_halt(struct usb_ep *_ep, int value)
{
struct lpc32xx_ep *ep = container_of(_ep, struct lpc32xx_ep, ep);
- struct lpc32xx_udc *udc = ep->udc;
+ struct lpc32xx_udc *udc;
unsigned long flags;

if ((!ep) || (ep->hwep_num <= 1))
@@ -1882,6 +1882,7 @@ static int lpc32xx_ep_set_halt(struct usb_ep *_ep, int value)
if (ep->is_in)
return -EAGAIN;

+ udc = ep->udc;
spin_lock_irqsave(&udc->lock, flags);

if (value == 1) {
--
2.20.1


2019-11-10 23:02:47

by Vladimir Zapolskiy

[permalink] [raw]
Subject: Re: [PATCH] usb: gadget: udc: lpc32xx: don't dereference ep until it has been null checked

On 11/11/2019 12:14 AM, Colin King wrote:
> From: Colin Ian King <[email protected]>
>
> The pointer ep is currently being dereferenced when initializing pointer
> udc before ep is being null checked. Fix this by only dereferencing
> ep after it has been null checked.
>
> Addresses-Coverity: ("Dereference before null check")
> Fixes: 24a28e428351 ("USB: gadget driver for LPC32xx")
> Signed-off-by: Colin Ian King <[email protected]>

Acked-by: Vladimir Zapolskiy <[email protected]>

--
Best wishes,
Vladimir