Skip to contentSkip to conversation

usb: gadget: aspeed_udc: fix handling of tx_len == 0

PATCH Superseded Dan Carpenter 3 participants 3 messages Jun 23, 2022 – Jun 24, 2022

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: gadget: aspeed_udc: fix handling of tx_len == 0

The bug is that we should still enter this loop if "tx_len" is zero.

Fixes c09b1f372e74 ("usb: gadget: aspeed_udc: cleanup loop in ast_dma_descriptor_setup()")

---
v2: Remove the unnecessary "chunk >= 0" condition

 drivers/usb/gadget/udc/aspeed_udc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/usb/gadget/udc/aspeed_udc.c +6 -3
index d75a4e070bf7..6ff02acc5662 100644
@@ -476,6 +476,7 @@ static int ast_dma_descriptor_setup(struct ast_udc_ep *ep, u32 dma_buf,
 {
 	struct ast_udc_dev *udc = ep->udc;
 	struct device *dev = &udc->pdev->dev;
+	bool last = false;
 	int chunk, count;
 	u32 offset;
 
@@ -493,14 +494,16 @@ static int ast_dma_descriptor_setup(struct ast_udc_ep *ep, u32 dma_buf,
 	       "tx_len", tx_len);
 
 	/* Create Descriptor Lists */
-	while (chunk > 0 && count < AST_UDC_DESCS_COUNT) {
+	while (!last && count < AST_UDC_DESCS_COUNT) {
 
 		ep->descs[ep->descs_wptr].des_0 = dma_buf + offset;
 
-		if (chunk > ep->chunk_max)
+		if (chunk > ep->chunk_max) {
 			ep->descs[ep->descs_wptr].des_1 = ep->chunk_max;
-		else
+		} else {
 			ep->descs[ep->descs_wptr].des_1 = chunk;
+			last = true;
+		}
 
 		chunk -= ep->chunk_max;
 
Signature · 1 line
2.35.1
maintainer
#1 lore raw
Quoted 8 lines

The bug is that we should still enter this loop if "tx_len" is zero.

Fixes c09b1f372e74 ("usb: gadget: aspeed_udc: cleanup loop in

ast_dma_descriptor_setup()")

---
v2: Remove the unnecessary "chunk >= 0" condition

I mean v1 looks good to me.
Sorry if you are misunderstanding.

Quoted 40 lines
 drivers/usb/gadget/udc/aspeed_udc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/usb/gadget/udc/aspeed_udc.c +6 -4
index d75a4e070bf7..6ff02acc5662 100644
@@ -476,6 +476,7 @@ static int ast_dma_descriptor_setup(struct ast_udc_ep
 *ep, u32 dma_buf,  {
 	struct ast_udc_dev *udc = ep->udc;
 	struct device *dev = &udc->pdev->dev;
+	bool last = false;
 	int chunk, count;
 	u32 offset;
 
@@ -493,14 +494,16 @@ static int ast_dma_descriptor_setup(struct
 ast_udc_ep *ep, u32 dma_buf,
 	       "tx_len", tx_len);
 
 	/* Create Descriptor Lists */
-	while (chunk > 0 && count < AST_UDC_DESCS_COUNT) {
+	while (!last && count < AST_UDC_DESCS_COUNT) {
 
 		ep->descs[ep->descs_wptr].des_0 = dma_buf + offset;
 
-		if (chunk > ep->chunk_max)
+		if (chunk > ep->chunk_max) {
 			ep->descs[ep->descs_wptr].des_1 = ep->chunk_max;
-		else
+		} else {
 			ep->descs[ep->descs_wptr].des_1 = chunk;
+			last = true;
+		}
 
 		chunk -= ep->chunk_max;
 
--

2.35.1

#2 lore raw
Quoted 11 lines · Neal Liu
Quoted 8 lines

The bug is that we should still enter this loop if "tx_len" is zero.

Fixes c09b1f372e74 ("usb: gadget: aspeed_udc: cleanup loop in

ast_dma_descriptor_setup()")

---
v2: Remove the unnecessary "chunk >= 0" condition

I mean v1 looks good to me.
Sorry if you are misunderstanding.

I have no idea if v1 or v2 is the "correct" one here, sorry.

Dan, can you send a v3 that you all agree on?

thanks,

greg k-h