From: Maoyi Xie <maoyixie.tju@gmail•com>
To: Andrew Jeffery <andrew@codeconstruct•com.au>,
Neal Liu <neal_liu@aspeedtech•com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation•org>,
Benjamin Herrenschmidt <benh@kernel•crashing.org>,
Joel Stanley <joel@jms•id.au>, Andrew Lunn <andrew@lunn•ch>,
Alan Stern <stern@rowland•harvard.edu>,
linux-aspeed@lists•ozlabs.org,
linux-arm-kernel@lists•infradead.org, linux-usb@vger•kernel.org,
linux-kernel@vger•kernel.org
Subject: [PATCH v3] usb: gadget: aspeed_udc: avoid past-the-end iterator in dequeue
Date: Thu, 21 May 2026 14:54:28 +0800 [thread overview]
Message-ID: <20260521065428.3261238-1-maoyixie.tju@gmail.com> (raw)
In-Reply-To: <20260519080213.1932516-1-maoyixie.tju@gmail.com>
ast_udc_ep_dequeue() declares the loop cursor `req` outside the
list_for_each_entry(). After the loop it tests `&req->req != _req`
to decide whether the request was found. If the queue holds no
match, `req` is past-the-end. It then aliases
container_of(&ep->queue, struct ast_udc_request, queue) via offset
cancellation. Whether that synthetic address equals `_req` depends
on heap layout. The function can return 0 without dequeueing
anything.
Default `rc` to -EINVAL and set it to 0 only inside the match
branch. `req` is no longer read after the loop, so the past-the-end
dereference goes away. No extra cursor variable or post-loop test
is needed.
Suggested-by: Alan Stern <stern@rowland•harvard.edu>
Suggested-by: Andrew Jeffery <andrew@codeconstruct•com.au>
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail•com>
---
v3: Switch to Andrew Jeffery's shape: default rc to -EINVAL, set
rc=0 inside the match branch, drop the post-loop check. Smaller
diff, no extra cursor variable, no goto. Same semantic fix as v2.
v2: https://lore.kernel.org/linux-usb/20260519080213.1932516-1-maoyixie.tju@gmail.com/
v1: https://lore.kernel.org/linux-usb/20260518073403.1285339-1-maoyi.xie@ntu.edu.sg/
drivers/usb/gadget/udc/aspeed_udc.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/gadget/udc/aspeed_udc.c b/drivers/usb/gadget/udc/aspeed_udc.c
index 7fc6696b7694..75f9c831b21a 100644
--- a/drivers/usb/gadget/udc/aspeed_udc.c
+++ b/drivers/usb/gadget/udc/aspeed_udc.c
@@ -694,7 +694,7 @@ static int ast_udc_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
struct ast_udc_dev *udc = ep->udc;
struct ast_udc_request *req;
unsigned long flags;
- int rc = 0;
+ int rc = -EINVAL;
spin_lock_irqsave(&udc->lock, flags);
@@ -704,14 +704,11 @@ static int ast_udc_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
list_del_init(&req->queue);
ast_udc_done(ep, req, -ESHUTDOWN);
_req->status = -ECONNRESET;
+ rc = 0;
break;
}
}
- /* dequeue request not found */
- if (&req->req != _req)
- rc = -EINVAL;
-
spin_unlock_irqrestore(&udc->lock, flags);
return rc;
--
2.34.1
prev parent reply other threads:[~2026-05-21 6:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-18 7:34 [PATCH] usb: gadget: aspeed_udc: avoid past-the-end iterator in dequeue Maoyi Xie
2026-05-18 21:43 ` Alan Stern
2026-05-19 8:02 ` [PATCH v2] " Maoyi Xie
2026-05-20 2:01 ` Andrew Jeffery
2026-05-21 6:54 ` Maoyi Xie [this message]
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=20260521065428.3261238-1-maoyixie.tju@gmail.com \
--to=maoyixie.tju@gmail$(echo .)com \
--cc=andrew@codeconstruct$(echo .)com.au \
--cc=andrew@lunn$(echo .)ch \
--cc=benh@kernel$(echo .)crashing.org \
--cc=gregkh@linuxfoundation$(echo .)org \
--cc=joel@jms$(echo .)id.au \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
--cc=linux-aspeed@lists$(echo .)ozlabs.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linux-usb@vger$(echo .)kernel.org \
--cc=neal_liu@aspeedtech$(echo .)com \
--cc=stern@rowland$(echo .)harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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