[PATCH] usb: dwc2: host: Do not map buffer on zero len packet
Jules Maselbas
jmaselbas at kalray.eu
Mon Nov 22 09:31:23 PST 2021
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 at 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
More information about the barebox
mailing list