usb: musb: gadget: prevent a NULL pointer dereference
authorFelipe Balbi <balbi@ti.com>
Wed, 1 Dec 2010 09:03:54 +0000 (11:03 +0200)
committerFelipe Balbi <balbi@ti.com>
Wed, 1 Dec 2010 09:03:54 +0000 (11:03 +0200)
Case we can't allocate struct musb_request,
prevent a NULL pointer dereference by returning
early.

Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/musb/musb_gadget.c

index 5d815049cbaac4796617ed9e1ae4e0aa6e29a668..edff014edd3af5780aa7edcb3838fb861aa76549 100644 (file)
@@ -1072,13 +1072,16 @@ struct usb_request *musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
        struct musb_request     *request = NULL;
 
        request = kzalloc(sizeof *request, gfp_flags);
-       if (request) {
-               INIT_LIST_HEAD(&request->request.list);
-               request->request.dma = DMA_ADDR_INVALID;
-               request->epnum = musb_ep->current_epnum;
-               request->ep = musb_ep;
+       if (!request) {
+               DBG(4, "not enough memory\n");
+               return NULL;
        }
 
+       INIT_LIST_HEAD(&request->request.list);
+       request->request.dma = DMA_ADDR_INVALID;
+       request->epnum = musb_ep->current_epnum;
+       request->ep = musb_ep;
+
        return &request->request;
 }