From: Dan Carpenter <dan.carpenter@oracle.com>
To: Neal Liu <neal_liu@aspeedtech.com>
Cc: Felipe Balbi <balbi@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Joel Stanley <joel@jms.id.au>, Andrew Jeffery <andrew@aj.id.au>,
linux-aspeed@lists.ozlabs.org, linux-usb@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: [PATCH] usb: gadget: aspeed_udc: fix handling of tx_len == 0
Date: Wed, 22 Jun 2022 17:50:59 +0300 [thread overview]
Message-ID: <YrMsU9HvdBm5YrRH@kili> (raw)
The bug is that we should still enter this loop if "tx_len" is zero.
After adding the "last" variable, then the "chunk >= 0" condition is no
longer required but I left it for readability.
Reported-by: Neal Liu <neal_liu@aspeedtech.com>
Fixes: c09b1f372e74 ("usb: gadget: aspeed_udc: cleanup loop in ast_dma_descriptor_setup()")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/usb/gadget/udc/aspeed_udc.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/gadget/udc/aspeed_udc.c b/drivers/usb/gadget/udc/aspeed_udc.c
index d75a4e070bf7..01968e2167f9 100644
--- a/drivers/usb/gadget/udc/aspeed_udc.c
+++ b/drivers/usb/gadget/udc/aspeed_udc.c
@@ -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 (chunk >= 0 && !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
next reply other threads:[~2022-06-22 14:51 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-22 14:50 Dan Carpenter [this message]
2022-06-23 1:41 ` [PATCH] usb: gadget: aspeed_udc: fix handling of tx_len == 0 Neal Liu
2022-06-23 6:43 ` Dan Carpenter
2022-06-23 7:22 ` Dan Carpenter
2022-06-23 7:52 ` Neal Liu
2022-06-23 7:55 ` Dan Carpenter
2022-06-23 8:37 ` Neal Liu
2022-06-24 6:17 ` Herrenschmidt, Benjamin
2022-06-24 6:34 ` Dan Carpenter
2022-06-24 6:39 ` Benjamin Herrenschmidt
2022-06-24 7:46 ` Neal Liu
2022-06-27 1:30 ` Benjamin Herrenschmidt
2022-06-28 7:17 ` Neal Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YrMsU9HvdBm5YrRH@kili \
--to=dan.carpenter@oracle.com \
--cc=andrew@aj.id.au \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=joel@jms.id.au \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-aspeed@lists.ozlabs.org \
--cc=linux-usb@vger.kernel.org \
--cc=neal_liu@aspeedtech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox