From nobody Mon May 25 03:33:27 2026 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 796BD3DFC80 for ; Tue, 19 May 2026 08:02:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779177741; cv=none; b=fAmzxtIkoC/8DTBCpT5vTHjlucjG4gYC9MH221L6jDVjEPLYjL89k175T7ggO9Vnv2ntML6/brAVjSKDeiDL+4u1G/VJtgvmm5NLLTOo+V4Dk0qEQzeNCzrV3eogOpGyZreIZrpAz01W8lLf8igdcff+zNaFAeEGdSHgumOWTZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779177741; c=relaxed/simple; bh=TqLfvbGm6KWphZeDm5azOd7a/CiRfeYYJT4IxTyXTrI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RyCBVb1uO+yb5Nmwu4K2Yh/oHrmbsjTqXHBnknxGQh13BfykPZmMZ9nDGF+lzLelPNpCcg5hw6bRluQ2wgmmzwo9XnDTq/AR4H6nOWSBF0fYnDNT/HGXQdk6P6eZL6di8hUCsvR2BjfGixOpQc3+gqe/SgN4HKRf3XD2Hjn6lNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=knMF0rMG; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="knMF0rMG" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-c80167f5716so1321211a12.2 for ; Tue, 19 May 2026 01:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779177740; x=1779782540; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p+hlBWVPQXy43hiRxqKhCnwnHHiHzFjw8+7rkTfE8vA=; b=knMF0rMGSeU76JLUq33zcd5U71jBT0p2yEYxSnuGqSKcXX7cHvaCDajri6A3Xp0u9f v7euF6XOqc96A+07/uJWyPEIE/RJXvRO7cBWi6a1+1F4q2i3au7zhIFAjbAGW++arUCj +EVuduPJcM8pYyXZNhsgBp8/9neLTlh63XOEiX3Jk+8atYy3HfT2LMfZCRfXyl487RO5 qhAfCqha7pAjhTxOlp9JCQfZ/n1fIjZbupPgpq02YEDg+TXVVAOuEjsF6xTTkS3NMnnd gsEH5ry4JkhTJUpIlbPoP+Jrurk+x1Zte8zPfqj9WE59SwNhVeIwzLO7V+3pijU1VWQQ Q8zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779177740; x=1779782540; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=p+hlBWVPQXy43hiRxqKhCnwnHHiHzFjw8+7rkTfE8vA=; b=oFHBHRRLLgwwOqiaUuePVAsjjyo443eQA+qsJ2LzjXz1Y60o/yL5XNjEaCihfpZ9+d gVt0w3/5Z8nCAgRVBJuFcdr9ROsBhi9m9pOyzT93JEN6F9ghbGOq96HPqVNincQqFHwS 5Pn8/PJltAO6AGW1OQPumXDi9m3Sg8+BJm0zJ3aTEErY2LOKg/e7cbvIA2s2xCCs77ko 52yVYkd9f9rfzm52phoKiG6uArvRZpi5VBO6oK4Lj/IgVLx1kp5RHz4lI4F6bzqEQaOu 5Cyh6WY7Dih0ysn/yT7AykkmKPJbkPEWDsE2UJ43UObaXBLXE2mKweQZp7T1C1PKgSJj VzFg== X-Forwarded-Encrypted: i=1; AFNElJ8xvYmappE3XlyHXzEb7i3yIx4cdXtjfzghTEpl8/+cfPMPS2EZqMx1jAxjku8zi2N7cVjVx7nKUTD+XKA=@vger.kernel.org X-Gm-Message-State: AOJu0YydOC25Q7wiYQCFoMjbaPDZuAcuzYyQaVwoXDx/udui6xlA4ZLY xtU0X0+pDsYDC7ueH8LziAt1wDb4+ra1Td0aHeE8orOZYR4HTqMecxkR X-Gm-Gg: Acq92OFduvMA+tE/FBOvPw63eaNhMrtCmhJbI8u0K/2dzHLPIrEEqCV02/B6GunO1u5 6WCazQsfFAKjPueJBUPdz/9Cmo3hO3s0QmblKh2jmlVmerrweHu/UeRzleUiO+7XP8XWnknarO0 GOTYVO8n1vDwcHwcOMqsXm7ccI1e0LpJw8c2bLosnp2YRMu3wS/MFO8LROnT/VZZNE18eU2u31t DNUf8SYb52tD+qk6S+l4glw4eR2S55CsduYTBBcGKRW4ogjQ2y5he0tgBvdjPSdWT7pt0f2LYyQ ES1XIGHLE1UDaf5j4tCEcNeB691N/gkldrb7Zid+9VyF/jPEZYoeXQXZsEVipIf7IpsuIizz4ef A1oC4pIPtCUvRPfzreiZKME8QhCAjEQHZynLBLPgjY8S030FCgOm1anfDfC3epEW3RvvOi42+Uu LEEMmR+nEc9t9s/cOtUvIxfA1qXDuGIdwWR5osBuqEh8KXBTlH X-Received: by 2002:a17:902:7206:b0:2b7:aa20:3c61 with SMTP id d9443c01a7336-2bd7e8cb16bmr129248565ad.33.1779177739786; Tue, 19 May 2026 01:02:19 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2bd5d0f8efesm181857735ad.55.2026.05.19.01.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 01:02:18 -0700 (PDT) From: Maoyi Xie To: Andrew Jeffery , Neal Liu Cc: Greg Kroah-Hartman , Benjamin Herrenschmidt , Joel Stanley , Andrew Jeffery , Alan Stern , linux-aspeed@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] usb: gadget: aspeed_udc: avoid past-the-end iterator in dequeue Date: Tue, 19 May 2026 16:02:13 +0800 Message-Id: <20260519080213.1932516-1-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260518073403.1285339-1-maoyi.xie@ntu.edu.sg> References: <20260518073403.1285339-1-maoyi.xie@ntu.edu.sg> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ast_udc_ep_dequeue() declares the loop cursor `req` outside the list_for_each_entry(). After the loop it tests `&req->req !=3D _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. Walk the list with a separate `iter`. Set `req` only when a request matches. After the loop, `req` is NULL if nothing matched. Suggested-by: Alan Stern Signed-off-by: Maoyi Xie --- v2: Switch the loop body to Alan Stern's shape: test inside the if, assign `req`, break. Same behaviour as v1. v1: https://lore.kernel.org/linux-usb/20260518073403.1285339-1-maoyi.xie@nt= u.edu.sg/ drivers/usb/gadget/udc/aspeed_udc.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/drivers/usb/gadget/udc/aspeed_udc.c 2026-05-19 15:29:28.690931576 +08= 00 +++ b/drivers/usb/gadget/udc/aspeed_udc.c 2026-05-19 15:29:59.482953528 +08= 00 @@ -692,26 +692,30 @@ { struct ast_udc_ep *ep =3D to_ast_ep(_ep); struct ast_udc_dev *udc =3D ep->udc; - struct ast_udc_request *req; + struct ast_udc_request *req =3D NULL, *iter; unsigned long flags; int rc =3D 0; =20 spin_lock_irqsave(&udc->lock, flags); =20 /* make sure it's actually queued on this endpoint */ - list_for_each_entry(req, &ep->queue, queue) { - if (&req->req =3D=3D _req) { - list_del_init(&req->queue); - ast_udc_done(ep, req, -ESHUTDOWN); - _req->status =3D -ECONNRESET; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req =3D=3D _req) { + req =3D iter; break; } } =20 - /* dequeue request not found */ - if (&req->req !=3D _req) + if (!req) { rc =3D -EINVAL; + goto out; + } + + list_del_init(&req->queue); + ast_udc_done(ep, req, -ESHUTDOWN); + _req->status =3D -ECONNRESET; =20 +out: spin_unlock_irqrestore(&udc->lock, flags); =20 return rc; --=20 2.34.1