Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3555755pxp; Tue, 8 Mar 2022 17:21:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2qj0rffnC3a145SevR3xr7m6svAbLmDPY0NAVnW0uTZJUrG+HajEVnpmE0qOwpvoDbZJH X-Received: by 2002:a63:3d48:0:b0:374:4b15:76e4 with SMTP id k69-20020a633d48000000b003744b1576e4mr16049157pga.593.1646788886717; Tue, 08 Mar 2022 17:21:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646788886; cv=none; d=google.com; s=arc-20160816; b=DpN59VUwwWCJ/dS6jK79V3EeTxO0XH4Ge1+CRlUfuw1H171LWWJiIe2LpVo1UYt6tt WpSfPguy83TSqw6GIx0ZdUpKJp2vFWD5Bf4BiJEjWWVrbEqwGWfpq8GCedghKL2W1cY5 yFUUrdRY8LM0kJXDjFWUW5DRuPk4cdP+vJgCW6nCugr3u0KiqR3c42jp8cCITnSVrHVN 3nyy26vY2KuMJIic4GeOKIdo9iVHLcpLxrmgLj4yE58BwoEmO5AjNw0WKwXEgTYwoTkB ybzsawcUcWUilF/Su+IV7eBi8e1jJ2HSxrfalPIir/VotYE0DOTBt6lv4zM5lPDKPdNY d7RQ== 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=5DfRiN4tVEInDy1EaFlW5SfOWSz7K0FfgTOmN6xKLdM=; b=O5wEndCWPz77OlIgn0rbEpSiJbmo8bY2zn5OgngLPa73rrN17vJNcelDf+sNbSwyRC HqfnzV+Qr85sRND0X2Y+sBBjGJFbGYXcFlYFN+ZqkDJ1qvwvax2TCdTt03d2Dytn1FGH 2lJL5+AFmHZ1gKVjBztJfmHFgOE4LB/xfq53jeLB8W/WPHQ8QR1H6mUUAiyi72nMxyp5 W3Gu8qDzLj2n8pKQK/GV/+IAVteYiN+kgQyddUXC8+Z19iOxpPrGpS6vl1lve3ehfXCF NLWgYzptkAyanaHDFXc8hi7qLV0KA44NIiRVShwseEbGZLkvz5+9wxBQe5Gm9ViIW/Si wMtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hb8FdLB1; 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 g14-20020a63564e000000b0035dc2c65f0csi427381pgm.364.2022.03.08.17.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 17:21:26 -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=hb8FdLB1; 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 A0797190B4D; Tue, 8 Mar 2022 16:14:37 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348324AbiCHRVf (ORCPT + 99 others); Tue, 8 Mar 2022 12:21:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348808AbiCHRUd (ORCPT ); Tue, 8 Mar 2022 12:20:33 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59FC453E38; Tue, 8 Mar 2022 09:19:23 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id h13so13273601ede.5; Tue, 08 Mar 2022 09:19:23 -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=5DfRiN4tVEInDy1EaFlW5SfOWSz7K0FfgTOmN6xKLdM=; b=hb8FdLB1uM1UKpdPJwEPXncuuxGUo2wvVu7FMZEvId0f8lNvB/SYyf1WG2N9sZqfgp ONf7EkT/5NFZRrkb5nZcHlTkEo823pCm229yUB6t5pBkzC1esqh+mgWnQK8xOSFYYZT+ +9GwTybV0FJolqLU3f8kcJNlLvprhGzYJvvpzJsY7W+87+U/bZmQW1T5FDOQ8v+1jXkB gAlEw/HpCrkJSnRrdngIzrJhdeTzyVHDfDbKTNcUuTsWXSiCmxH+HCpBYEep5Rhu0nV2 GqWyn+Bau4wVoJdugkzsVR1UK3q4PwowaO3X7DIm+6IFxAdgcE1R9uXrwu0GXTL7JfIp Q5hw== 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=5DfRiN4tVEInDy1EaFlW5SfOWSz7K0FfgTOmN6xKLdM=; b=VrqAIXxQpT8vBi6DBLCg9738M0rMxT2lHPOBlufdtmz2RQL+Sza/yWjwVn1sPOPTUH Y2sDNfJneOLcuYuJfL03nSFJATpk4SrZ/6C3VFUQ2XR43WNRpCJr73zviPi581PXUZCP k0v4pdAJBgcDoQCs7zfWZH+JeZ0z/N9eGW2m9gLrWZeBNOLe5OWZ5U17qc5GExZtKJDC yWHShY6wPLLoNU58T5HDU5Yd3Q65vL9fZSKIDVMhYrjaTEwCna7pNmmVkFXEjYMyYMXA Ee1Hvge4Zkqq+iHhISNC8DqSBFjcu6usW6sJ+bEzq0FJD1Q94TPLR3HGhSK3aaHkJx1b M7hA== X-Gm-Message-State: AOAM532HEzucO7Z+xPGLlgLFD7c9wksMpYTvvST0RjIgxJx6sXN4MX8K PXc2IYn308pyNEIIzCsha/c= X-Received: by 2002:aa7:c3d8:0:b0:415:a0a9:1f18 with SMTP id l24-20020aa7c3d8000000b00415a0a91f18mr16877614edr.412.1646759961620; Tue, 08 Mar 2022 09:19:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:21 -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 13/26] usb: gadget: omap_udc: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:05 +0100 Message-Id: <20220308171818.384491-14-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/omap_udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c index 494da00398d7..2d9815dad2ff 100644 --- a/drivers/usb/gadget/udc/omap_udc.c +++ b/drivers/usb/gadget/udc/omap_udc.c @@ -1003,7 +1003,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) static int omap_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); - struct omap_req *req; + struct omap_req *req = NULL, *iter; unsigned long flags; if (!_ep || !_req) @@ -1012,11 +1012,13 @@ static int omap_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