All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: dwc2: host: Check for error map
@ 2021-12-24  3:18 Jiasheng Jiang
  2021-12-24  8:48 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Jiasheng Jiang @ 2021-12-24  3:18 UTC (permalink / raw)
  To: hminas, gregkh; +Cc: linux-usb, linux-kernel, Jiasheng Jiang

For the possible failure of the dma_map_single(), it should be better to
check the return map address by using dma_mapping_error() to guarantee
the valid of the map address.

Fixes: 197ba5f406cc ("Move DWC2 driver out of staging")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/usb/dwc2/hcd_ddma.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/hcd_ddma.c b/drivers/usb/dwc2/hcd_ddma.c
index a858b5f9c1d6..89ed93a67c8a 100644
--- a/drivers/usb/dwc2/hcd_ddma.c
+++ b/drivers/usb/dwc2/hcd_ddma.c
@@ -143,6 +143,7 @@ static void dwc2_desc_list_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
 
 static int dwc2_frame_list_alloc(struct dwc2_hsotg *hsotg, gfp_t mem_flags)
 {
+	dma_addr_t addr;
 	if (hsotg->frame_list)
 		return 0;
 
@@ -151,9 +152,13 @@ static int dwc2_frame_list_alloc(struct dwc2_hsotg *hsotg, gfp_t mem_flags)
 	if (!hsotg->frame_list)
 		return -ENOMEM;
 
-	hsotg->frame_list_dma = dma_map_single(hsotg->dev, hsotg->frame_list,
-					       hsotg->frame_list_sz,
-					       DMA_TO_DEVICE);
+	addr = dma_map_single(hsotg->dev, hsotg->frame_list,
+			      hsotg->frame_list_sz,
+			      DMA_TO_DEVICE);
+	if (dma_mapping_error(hsotg->dev, addr))
+		return -ENOMEM;
+
+	hsotg->frame_list_dma = addr;
 
 	return 0;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-24  8:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-24  3:18 [PATCH] usb: dwc2: host: Check for error map Jiasheng Jiang
2021-12-24  8:48 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.