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

* Re: [PATCH] usb: dwc2: host: Do not map buffer on zero len packet
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2021-11-25  7:45 UTC (permalink / raw)
  To: Jules Maselbas; +Cc: barebox

On Mon, Nov 22, 2021 at 06:31:23PM +0100, Jules Maselbas wrote:
> 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(-)

Applied to master, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
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

mail archive of the barebox mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lore.barebox.org/barebox/0 barebox/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 barebox barebox/ https://lore.barebox.org/barebox \
		barebox@lists.infradead.org
	public-inbox-index barebox

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git