All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiasheng Jiang <jiasheng@iscas.ac.cn>
To: hminas@synopsys.com, gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jiasheng Jiang <jiasheng@iscas.ac.cn>
Subject: [PATCH] usb: dwc2: host: Check for error map
Date: Fri, 24 Dec 2021 11:18:42 +0800	[thread overview]
Message-ID: <20211224031842.1564705-1-jiasheng@iscas.ac.cn> (raw)

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


             reply	other threads:[~2021-12-24  3:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-24  3:18 Jiasheng Jiang [this message]
2021-12-24  8:48 ` [PATCH] usb: dwc2: host: Check for error map Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211224031842.1564705-1-jiasheng@iscas.ac.cn \
    --to=jiasheng@iscas.ac.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=hminas@synopsys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.