mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] usb: dwc2: host: Do not map buffer on zero len packet
@ 2021-11-22 17:31 Jules Maselbas
  2021-11-25  7:45 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Jules Maselbas @ 2021-11-22 17:31 UTC (permalink / raw)
  To: barebox; +Cc: Jules Maselbas

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


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

end of thread, other threads:[~2021-11-25  7:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 17:31 [PATCH] usb: dwc2: host: Do not map buffer on zero len packet Jules Maselbas
2021-11-25  7:45 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox