Skip to content

Commit

Permalink
staging: emxx_udc: Add checks for dma_alloc_coherent()
Browse files Browse the repository at this point in the history
[ Upstream commit f6510a93cfd8c6c79b4dda0f2967cdc6df42eff4 ]

As the dma_alloc_coherent may return NULL, the return value needs to be
checked to avoid NULL poineter dereference.

Signed-off-by: Yuan Can <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Yuan Can authored and gregkh committed Mar 11, 2023
1 parent 6683327 commit 4be3213
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/staging/emxx_udc/emxx_udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2590,10 +2590,15 @@ static int nbu2ss_ep_queue(struct usb_ep *_ep,
req->unaligned = false;

if (req->unaligned) {
if (!ep->virt_buf)
if (!ep->virt_buf) {
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,
Expand Down

0 comments on commit 4be3213

Please sign in to comment.