Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3582544pxp; Tue, 8 Mar 2022 18:02:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJyo+JepJGFo76V3WcXSzBKeT/aGIN8jpvTBfl8l14pYA67lebuwi2UCTYWK1RzOF/sl2hRM X-Received: by 2002:a05:6a00:1ac6:b0:4bd:140:626c with SMTP id f6-20020a056a001ac600b004bd0140626cmr21091637pfv.7.1646791372700; Tue, 08 Mar 2022 18:02:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646791372; cv=none; d=google.com; s=arc-20160816; b=dyJq6xbEZLHX+tS3n8Evsv+haLOlK8rVEh9n6/o7uaTjFFLLkSZT6DW1K0r+Mtof2b Q4LNza4D/xgOVeYuFBbQF2hHezZCDeM5gEgOnhBZ7vVaW/yExqScF2nDkqeL6iMY/o7R NnRtOVva4uV7fZmSvA8FrmbsxzD4RP0Ct+Dn7i1tJLm/+beTX2xYXJFcxcken60RgypW BHQV3QrhZJGsyWtVfJGCItiugE6IzibThyY04fvScVrnzPRNNJIVivyTWstY/r1KhOWI wGJD51LHMp5ixPf63+rU6gMqRicY6T2nz6kL8DNMlwoYwki8SCbQ/ey/8k9OpXDfu/E7 Nm+Q== 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=1x89pBzvXuUZrfPfd2vnoyMWt4N2rOHe1CTdgdRQIBk=; b=LSx26ZedFn/1gU5IqNROCGkvTe4IXC2xQquO7J+DOEPHbW6+Xk8Q1Mm7mLEKO2M54o tqS3sAKJPbgOA/k64C+zXoer3TkItkjcvnE4eTcVb7J+MbD3dMfhwwZFzIFkwDUKs919 ql+ERTxCMyGJDJQQjc/i5/vUCROONr5JrHLWQ5KBNoVzL9GVd8adx+9IdlE0T8cHLwRC xcCPfTy6p4nHg6yofmkiiA1aIYC45QDgltymdWPkYno3/x9hPftq5uvc/TGS2wEe5WZt VnFDc/Bkl1OUl3215m3cnp7U/xjs5cUzGEHd/wcAuwzg03xGF+B1qHuEIPa2K80P6ULb vf/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CqwLW0Hz; 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 c6-20020a170902d48600b00151cea965ffsi631115plg.471.2022.03.08.18.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 18:02:52 -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=CqwLW0Hz; 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 A6969238932; Tue, 8 Mar 2022 16:36:28 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349153AbiCHRVj (ORCPT + 99 others); Tue, 8 Mar 2022 12:21:39 -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-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 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/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__); -- 2.25.1