From: Jules Maselbas <jmaselbas@kalray.eu>
To: barebox@lists.infradead.org
Cc: Jules Maselbas <jmaselbas@kalray.eu>
Subject: [PATCH] usb: dwc2: host: Do not map buffer on zero len packet
Date: Mon, 22 Nov 2021 18:31:23 +0100 [thread overview]
Message-ID: <20211122173123.17252-1-jmaselbas@kalray.eu> (raw)
The transfer_chunk can be called for zero length packet, in such case
the buffer pointer is NULL and can fail to be mapped for the device.
In such case the device DMA address can be directly set to 0, as the
buffer address should be NULL anyway, without calling map/unmap at all.
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
drivers/usb/dwc2/host.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/dwc2/host.c b/drivers/usb/dwc2/host.c
index b5a51f5668..6726ff60db 100644
--- a/drivers/usb/dwc2/host.c
+++ b/drivers/usb/dwc2/host.c
@@ -169,10 +169,11 @@ static int transfer_chunk(struct dwc2 *dwc2, u8 hc,
int xfer_len, int *actual_len, int odd_frame)
{
uint32_t hctsiz, hcchar, sub;
- dma_addr_t dma_addr;
+ dma_addr_t dma_addr = 0;
int ret = 0;
- dma_addr = dma_map_single(dwc2->dev, buffer, xfer_len,
+ if (xfer_len)
+ dma_addr = dma_map_single(dwc2->dev, buffer, xfer_len,
in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
if (dma_mapping_error(dwc2->dev, dma_addr)) {
@@ -213,7 +214,8 @@ static int transfer_chunk(struct dwc2 *dwc2, u8 hc,
*actual_len = xfer_len;
exit:
- dma_unmap_single(dwc2->dev, dma_addr, xfer_len,
+ if (xfer_len)
+ dma_unmap_single(dwc2->dev, dma_addr, xfer_len,
in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
return ret;
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2021-11-22 17:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-22 17:31 Jules Maselbas [this message]
2021-11-25 7:45 ` Sascha Hauer
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=20211122173123.17252-1-jmaselbas@kalray.eu \
--to=jmaselbas@kalray.eu \
--cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox