From patchwork Tue Mar 8 17:18:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 550057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C75C3C433F5 for ; Tue, 8 Mar 2022 17:20:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242069AbiCHRU7 (ORCPT ); Tue, 8 Mar 2022 12:20:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244472AbiCHRUb (ORCPT ); Tue, 8 Mar 2022 12:20:31 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAD2053B4F; Tue, 8 Mar 2022 09:19:21 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id q17so25425577edd.4; Tue, 08 Mar 2022 09:19:21 -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=1x89pBzvXuUZrfPfd2vnoyMWt4N2rOHe1CTdgdRQIBk=; b=CqwLW0HzXtny0uR8QmiWKYWH71xfwPXsvjGDJmOI+H1S7fXG94E92RbG0/RSjBLbZz wOzQzVMuExNIn+ntof9qnJuIqQVc0ryKecRsCwRdoxQ490atw7nk+JduUsu9oL/QNoXU ao17nfTKYxINgLtLy3sBmWClKm16Rw8oFNX35B275n6sPCHCOfkxnxaGgvLhTN9mJqhv TptbxEX1Aci/BDeFs0wKxuMZ//RPiWMLG9v1L1SLK8TtfW06A9SAjj1Kds2WqxtjOuzh lDO4OKALloSiywOC4aGb8wKE8OZhweohCvfYMkENj7MsEBPmUMQ7Zl1XZ3z4VqxPuNjZ YO8w== 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=1x89pBzvXuUZrfPfd2vnoyMWt4N2rOHe1CTdgdRQIBk=; b=a1vBU5jlLd4x7Ojhs6gEtZ8EbZnOHNPI+CiHCIEwU7kenRT2DJW8czHsSMc06YgMXS mL0M7HSFXPanZV4dVDcIprF82f205UiCOY4p0VDKzAuRH2B1ezIfQHRWFqXCXdSjDArQ 6lnTgH85TrYIWmZXgam+xtEE9NSBzRFWhWEc/ooFAsnU+32IxWpMPDQLdrkdKLpMXsdf 1QbOQK0TBe1tILaqzvXzjeHREgl0jOhenN6cz5bnpBx4ftJ59AqxgnZV7w18/xtak/b0 H2mD1z1mc6oIg4BwmVcCMeUk2WCA0NA8RSUfr2vcbLTUkZt/nf24fb2bEotVADnHe0vG UyQQ== X-Gm-Message-State: AOAM530fYTOKnQct9qtBMKD033EO+bpBpLjujuLP4wtkRFr5oyqYocUq IiXursBj7xeTV0C1Te6KoZI= X-Google-Smtp-Source: ABdhPJyYzbEjTcRWHRiyOXyo23qWETd0x7XVuzNY6tVPkyg+apzypsfIydk+P8ggPUYFphVZTJ0sWA== X-Received: by 2002:aa7:c946:0:b0:416:226f:f8a6 with SMTP id h6-20020aa7c946000000b00416226ff8a6mr8118515edt.360.1646759960161; Tue, 08 Mar 2022 09:19:20 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:19 -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 12/26] usb: gadget: udc: net2280: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:04 +0100 Message-Id: <20220308171818.384491-13-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 Precedence: bulk List-ID: X-Mailing-List: linux-usb@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/net2280.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index 16e7d2db6411..051d024b369e 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -1240,7 +1240,8 @@ static void nuke(struct net2280_ep *ep) static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct net2280_ep *ep; - struct net2280_request *req; + struct net2280_request *req = NULL; + struct net2280_request *iter; unsigned long flags; u32 dmactl; int stopped; @@ -1266,11 +1267,13 @@ static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req) } /* make sure it's still 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) { ep->stopped = stopped; spin_unlock_irqrestore(&ep->dev->lock, flags); ep_dbg(ep->dev, "%s: Request mismatch\n", __func__);