[PATCH] usb: dwc2: host: Do not map buffer on zero len packet

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux