staging: emxx_udc: Add checks for dma_alloc_coherent()
PATCH 1/1 staging: emxx_udc: Add checks for dma_alloc_coherent()
As the dma_alloc_coherent() may return NULL, the return value needs to be checked to avoid NULL poineter dereference.
--- drivers/staging/emxx_udc/emxx_udc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/staging/emxx_udc/emxx_udc.c +4 -0
@@ -2594,6 +2594,10 @@ static int nbu2ss_ep_queue(struct usb_ep *_ep, ep->virt_buf =dma_alloc_coherent (udc->dev,PAGE_SIZE , &ep->phys_buf,GFP_ATOMIC |GFP_DMA ); +if (!ep->virt_buf) { +spin_unlock_irqrestore (&udc->lock, flags); +return -ENOMEM ; + }if (ep->epnum >0 ) {if (ep->direct ==USB_DIR_IN ) memcpy(ep->virt_buf, req->req.buf,
Signature · 1 line
2.17.1
Greg KH
maintainerQuoted 14 lines · Yuan Can
As the
dma_alloc_coherent()may return NULL, the return value needs to be checked to avoid NULL poineter dereference.Fixes 33aa8d45a4fe ("staging: emxx_udc: Add Emma Mobile USB Gadget driver")Signed-off-by Yuan Can <[email protected]>--- drivers/staging/emxx_udc/emxx_udc.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/staging/emxx_udc/emxx_udc.c +0
-0
drivers/staging/emxx_udc/emxx_udc.c static int nbu2ss_ep_queue(struct usb_ep *_ep, · line 2600
Quoted 7 lines
drivers/staging/emxx_udc/emxx_udc.c +4
-0@@ -2594,6 +2594,10 @@ static int nbu2ss_ep_queue(struct usb_ep *_ep, ep->virt_buf =dma_alloc_coherent (udc->dev,PAGE_SIZE , &ep->phys_buf,GFP_ATOMIC |GFP_DMA ); +if (!ep->virt_buf) { +spin_unlock_irqrestore (&udc->lock, flags); +return -ENOMEM ; + }
This should be checked in the if statment, not outside of it, right?
thanks,
greg k-h
Quoted 10 lines · Greg KH
Quoted 9 lines · Yuan Can
As the
dma_alloc_coherent()may return NULL, the return value needs to be checked to avoid NULL poineter dereference.Fixes 33aa8d45a4fe ("staging: emxx_udc: Add Emma Mobile USB Gadget driver")Signed-off-by Yuan Can <[email protected]>--- drivers/staging/emxx_udc/emxx_udc.c | 4 ++++ 1 file changed, 4 insertions(+)
Quoted 13 lines
drivers/staging/emxx_udc/emxx_udc.c static int nbu2ss_ep_queue(struct usb_ep *_ep, · line 2600
Quoted 12 lines
drivers/staging/emxx_udc/emxx_udc.c +4
-0@@ -2594,6 +2594,10 @@ static int nbu2ss_ep_queue(struct usb_ep *_ep, ep->virt_buf =dma_alloc_coherent (udc->dev,PAGE_SIZE , &ep->phys_buf,GFP_ATOMIC |GFP_DMA ); +if (!ep->virt_buf) { +spin_unlock_irqrestore (&udc->lock, flags); +return -ENOMEM ; + }This should be checked in the if statment, not outside of it, right?
Yes, the next version will do the check just before the memcpy, thanks for the suggestion.
Signature · 2 lines
Best regards, Yuan Can