Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3538987pxp; Tue, 8 Mar 2022 16:58:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcP+r2T3pceNFbAzuafWmTq0B6KNldfPw+3hsrwhxG0wzDLBBjKeBXUgZiNgayc2eNCmVI X-Received: by 2002:a17:90b:1b46:b0:1bf:9e6e:de79 with SMTP id nv6-20020a17090b1b4600b001bf9e6ede79mr3481799pjb.68.1646787518403; Tue, 08 Mar 2022 16:58:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646787518; cv=none; d=google.com; s=arc-20160816; b=Lj17klbfldj8+VYEAJvrJqMHF+VLjVbal/r3roW9U2k0N6DCzJXDorQPCpuZJ6zb51 MjOyXsuRtOU8aYJtI+knm+RkcaKO9i+bwoZyM2sSlcg48Wp2msSKM/2aXb2ym2DiQ6/c 4ad1I7uadhT4OGODD7ATevBut/PMtcZ3WP19xR7caSpna8E5Eiq1kUU1ZwoQw4jzuLYs FqDcUqTyoisAkd8dDOtNYCjvkjxfF49obv0CQGAGh951alXudhOHAI1sP4CslvgJP3Uw 1/zc+G2/+Ln9XeLkmqxkvvqEWLMuWD9jljYE4fResWcsnhJ54c/tmzYLW7UkdAXAinAH mkvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=f7/gAw+DbnZtTNdfpuzCiVdL6RMHX2i8psNGo9On2wE=; b=LtG/QYSgaF6APpMy/Dfa+yJlDbGbWIWZXnLujOXJVsZZfNKhus7qBS1NJX42sR2a1S sEWcB0VlHtta0W93PZ544VAPmZNQPlDgX898VBd/u/24pvvghEjvhYpqWNk2ZLmSZHK6 YQ+VYuTOMzG4Mz0FpSSqMSSYvUQSh1fINtT8E+5FZXafO3yqIkeOYpblS2dKUPV/5D3k yfrdAaPIWafeBXNU1Ozx+6r7s6sf6PwfFW8b6h2Xgp7+b6HMs8wQBi5MsISCzW8q01nq Cm0FvWjPuL4jMkTQznDb27OGAxVSTiSdswUMMyaUsunXM9K5kvMEtzfZc2DribukLZaY pAQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lZBLD5iJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j11-20020a056a00174b00b004df7b9e0ebcsi419511pfc.368.2022.03.08.16.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 16:58:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lZBLD5iJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A6FF215D387; Tue, 8 Mar 2022 16:06:44 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349000AbiCHRVO (ORCPT + 99 others); Tue, 8 Mar 2022 12:21:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348921AbiCHRU2 (ORCPT ); Tue, 8 Mar 2022 12:20:28 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9463A53707; Tue, 8 Mar 2022 09:19:18 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id w4so22863337edc.7; Tue, 08 Mar 2022 09:19:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f7/gAw+DbnZtTNdfpuzCiVdL6RMHX2i8psNGo9On2wE=; b=lZBLD5iJRHwna6Pu9qZ7/2APxDtkJaKEHwNbE6+HMjiGuMvomc/1zMzNkJChwYwOUC wh89YneS2YEvD1/3E6YiYRkJbMfG14PYEDSfnKDOcxnRP86SWcxS+yh4s7WyQE2Mitu1 5RtmU2GidWXd6f7WiJashE9Qqgssg/o/2ZRHgnj8zz4nFdcijcP2eAfyDFXkg/VziKBp fqFqBR0KEsNPf44Sn9hQfNdXuWNfTxuGjgHy8vmo3vjX+y4J4MTqLR7vzKlkakM9kzyh AUOXbd9aDkpQYqCJqZ+9+RAw+U9zUkeKnbcGsk+a55lXbgYXhRF0rEFrElYYIkfkmzSO Jb8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f7/gAw+DbnZtTNdfpuzCiVdL6RMHX2i8psNGo9On2wE=; b=g17PkaMpt9TAdx2L0O3mzOxEf1emtmZgiIHHQJpoVLDbo8n1q6qUBNY70sE7DeJ2NY xkV/R84n4Mj5Ce2d7xcXo/7XH9/sfV5oyP/ufIcyGuWoW6n3KHVGO1rCkyjPpF0V9cw5 373QoDst4MsN1oBC8UoM0W6BO7+qo6/BYpH3Cx/jSmeLaBvEUvh6+QWxhZYoMKwv6rbr aLe7hMcV2VZCAYfIR+aAfjZcv7Cx6zxHuEUWIsFq+8NiGffS2aZuSmfu9dj4+9+E0hnc 6rn9wIuqjLgLKe/vd2AZDJfWNp86gXWQcXrskBvynl4k1jk2dei9eSXgcwl56qMK2zik O9Lw== X-Gm-Message-State: AOAM531qaDBFcffJL6y41oZRcxWqIfeUB2x4lRV103jaUA1aMSkVuCXi zW1emPXMKCHBcpahNcWyLP8= X-Received: by 2002:a05:6402:268a:b0:416:7ed0:3f86 with SMTP id w10-20020a056402268a00b004167ed03f86mr589970edd.255.1646759954659; Tue, 08 Mar 2022 09:19:14 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:14 -0800 (PST) From: Jakob Koschel To: Greg Kroah-Hartman Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Linus Torvalds , Felipe Balbi , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cristian Birsan , Al Cooper , Li Yang , Vladimir Zapolskiy , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , linux-usb@vger.kernel.org (open list:USB GADGET/PERIPHERAL SUBSYSTEM), Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH v2 08/26] usb: gadget: lpc32xx_udc: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:00 +0100 Message-Id: <20220308171818.384491-9-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/lpc32xx_udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c index a25d01c89564..6117ae8e7242 100644 --- a/drivers/usb/gadget/udc/lpc32xx_udc.c +++ b/drivers/usb/gadget/udc/lpc32xx_udc.c @@ -1830,7 +1830,7 @@ static int lpc32xx_ep_queue(struct usb_ep *_ep, static int lpc32xx_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct lpc32xx_ep *ep; - struct lpc32xx_request *req; + struct lpc32xx_request *req = NULL, *iter; unsigned long flags; ep = container_of(_ep, struct lpc32xx_ep, ep); @@ -1840,11 +1840,13 @@ static int lpc32xx_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&ep->udc->lock, flags); /* make sure it's actually queued on this endpoint */ - list_for_each_entry(req, &ep->queue, queue) { - if (&req->req == _req) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { spin_unlock_irqrestore(&ep->udc->lock, flags); return -EINVAL; } -- 2.25.1