* [PATCH v2] usb: gadget: aspeed_udc: fix handling of tx_len == 0
@ 2022-06-23 13:00 Dan Carpenter
2022-06-24 2:01 ` Neal Liu
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2022-06-23 13:00 UTC (permalink / raw)
To: Neal Liu
Cc: Felipe Balbi, Greg Kroah-Hartman, Joel Stanley, Andrew Jeffery,
linux-aspeed, linux-usb, kernel-janitors
The bug is that we should still enter this loop if "tx_len" is zero.
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>
---
v2: Remove the unnecessary "chunk >= 0" condition
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..6ff02acc5662 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 (!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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH v2] usb: gadget: aspeed_udc: fix handling of tx_len == 0
2022-06-23 13:00 [PATCH v2] usb: gadget: aspeed_udc: fix handling of tx_len == 0 Dan Carpenter
@ 2022-06-24 2:01 ` Neal Liu
2022-06-24 11:35 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Neal Liu @ 2022-06-24 2:01 UTC (permalink / raw)
To: Dan Carpenter
Cc: Felipe Balbi, Greg Kroah-Hartman, Joel Stanley, Andrew Jeffery,
linux-aspeed, linux-usb, kernel-janitors
> The bug is that we should still enter this loop if "tx_len" is zero.
>
> 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>
> ---
> v2: Remove the unnecessary "chunk >= 0" condition
I mean v1 looks good to me.
Sorry if you are misunderstanding.
>
> 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..6ff02acc5662 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 (!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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] usb: gadget: aspeed_udc: fix handling of tx_len == 0
2022-06-24 2:01 ` Neal Liu
@ 2022-06-24 11:35 ` Greg Kroah-Hartman
0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2022-06-24 11:35 UTC (permalink / raw)
To: Neal Liu
Cc: Dan Carpenter, Felipe Balbi, Joel Stanley, Andrew Jeffery,
linux-aspeed, linux-usb, kernel-janitors
On Fri, Jun 24, 2022 at 02:01:18AM +0000, Neal Liu wrote:
> > The bug is that we should still enter this loop if "tx_len" is zero.
> >
> > 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>
> > ---
> > 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-24 11:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23 13:00 [PATCH v2] usb: gadget: aspeed_udc: fix handling of tx_len == 0 Dan Carpenter
2022-06-24 2:01 ` Neal Liu
2022-06-24 11:35 ` Greg Kroah-Hartman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.