Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1768545pxp; Mon, 7 Mar 2022 01:51:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJxODyEMsb89GyG4/qqD6ZebaJw/pXgxc3adZnst58YbawL0wpniO4KqiOscz9MpKglGXBiO X-Received: by 2002:a17:907:9811:b0:6db:41de:ed89 with SMTP id ji17-20020a170907981100b006db41deed89mr164100ejc.486.1646646709832; Mon, 07 Mar 2022 01:51:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646646709; cv=none; d=google.com; s=arc-20160816; b=l37zzJKxo72gN6Cc5Qi3MfeHNenvkVvsZ4hOQjp8KFz/pFzSHv4HI39NyjHSIzROga a3aQXhqMYsX8cgXVX+8ILKXQdhEEuTZyaWhCGvNM/l2jhzfLmIBN/RyRe/gcn3hBgA9x fk/S6a7kAtB71ZZUUVnzd69fkbz+O/KSRsmMJ0Pu6ok2ag5VGrBkOtgwe8wieRhNylx6 301d44NwZW4RHNeJwvDf9b35hACs9Sb0jY0YsNYVBrSPLXw6dNnlLxm/jYA30r2uRpr5 Z8z8MJCmXmt1qXiOKBOqxfyU8jAzgxbAcqzP3pA/Y5iXHMMA5XzA5uuzVjtF1+L0F1xt fqwA== 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=utzkgFEY4qR62mpmuTqoKbVS/KHHWuTcrin4SG2ItLk=; b=RbeUXMmmloBzpvpolSHt26L5bYlYlKWuZ4oMWWFde0xpoSd6wgNFUAfBqgEcNHQJH7 QNuNixuaY6qdDNUSYAdKIX+IO7GH+z6/t3dEYjCTwcGIW8yrI6Adz4V/bxJHgF2s+8PY dOtwEVXO0lhPEc0EHCX+2LAe3By6E6FGrQ0CYglRzh3VC4QszpTgtj4e+82DimBoULDo 3iYAqN5fZgSPDBiDuYZVtMTKiTpMJCnh5vJha7qilYW8htw9faKOgSFa+YrSNDKKe8JG 6p/NqVIg6Ep21eNpcevnR/dco/wRNzAOrPywhML9r0+T14xQGM3kyj6WUA8UoXm/+yqf R9Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dU8nCpPN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a056402278900b00415d08cdac6si8956465ede.478.2022.03.07.01.51.27; Mon, 07 Mar 2022 01:51:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dU8nCpPN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233980AbiCFRwI (ORCPT + 99 others); Sun, 6 Mar 2022 12:52:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233964AbiCFRwG (ORCPT ); Sun, 6 Mar 2022 12:52:06 -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 5E96C3E5DD; Sun, 6 Mar 2022 09:51:13 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id x5so16955578edd.11; Sun, 06 Mar 2022 09:51:13 -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=utzkgFEY4qR62mpmuTqoKbVS/KHHWuTcrin4SG2ItLk=; b=dU8nCpPNeMYUssBxZy7S6AHFLVFKJLYOyJzP1aq7xOE0VDG28AJJQ4JnLwQlNXqMm5 0qqGBMSzlynThyYX6cLA2RUxJlqqAuvN4A7h5IHBf94FQzjMPnFY4SExqC+ybFGf0hXu jvqhC7ayw1jDIC8E7/KUazqmDvKZ9vxQft3xCKFz71dq9+OxJDaUHAM/uMiH5S+mArgP HiozY5edfBGQuDs0YA3hGbuJau3xKxv3V2pJ8qIFss8Ri4cTc7Nc80bKKEQSjy84bCae 8/ZjkTAA5zedjZVlMwVx0GOWBPcZycTn9XrrZnoTBN49WMk8MYd9jcerjP9+dG7L80xb OrUQ== 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=utzkgFEY4qR62mpmuTqoKbVS/KHHWuTcrin4SG2ItLk=; b=Pt21ktcwjkMUsR9opUw2S+DdnJ2xJc9+y/2lSEwG4Ef0Nd4ABQJGhtpEt3YWv/VZJj cC/1BTtkSZxQBSRJFlk7PxwW+ZaVZ3P+MIOnIFsG7u/mra7kS6kz/+usy5avUephkty7 H2lfQ6ao3QEjYKWOgMQW7MtwfH1EpK/tjIUHJagoFICHqzpZHLN8aByDh4DZsXFxFWLU Uu8ljUaWW51apP3ESwrYm6vLARkvs7Ckl1tL/6nD2qDKGQ+RcA0MVYn3H9R/QwpZCiBV E3Og1JHi5YMgcde4n5MjgcP1j52lk5isu06FD1msKEUbe6ZFFwX38OzzHIzZAtRNjpU8 7BYA== X-Gm-Message-State: AOAM531TypMy2YwVa//crvLuVpmmdrOumhPRVWip/lzIMVK+23vIFhYx HZyPefUq2fevKxS3OvEk8fVRDUb9kOO8s1ch X-Received: by 2002:a50:8708:0:b0:416:765:c4c4 with SMTP id i8-20020a508708000000b004160765c4c4mr7513658edb.245.1646589071949; Sun, 06 Mar 2022 09:51:11 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id 20-20020a17090601d400b006caff964e30sm4052606ejj.19.2022.03.06.09.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:11 -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 02/26] usb: gadget: bdc: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:10 +0100 Message-Id: <20220306175034.3084609-3-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220306175034.3084609-1-jakobkoschel@gmail.com> References: <20220306175034.3084609-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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/bdc/bdc_ep.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c b/drivers/usb/gadget/udc/bdc/bdc_ep.c index 8e2f20b12519..829e96791d0a 100644 --- a/drivers/usb/gadget/udc/bdc/bdc_ep.c +++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c @@ -1757,6 +1757,7 @@ static int bdc_gadget_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct bdc_req *req; + struct bdc_req *tmp; unsigned long flags; struct bdc_ep *ep; struct bdc *bdc; @@ -1771,12 +1772,16 @@ static int bdc_gadget_ep_dequeue(struct usb_ep *_ep, dev_dbg(bdc->dev, "%s ep:%s req:%p\n", __func__, ep->name, req); bdc_dbg_bd_list(bdc, ep); spin_lock_irqsave(&bdc->lock, flags); + + req = NULL; /* make sure it's still queued on this endpoint */ - list_for_each_entry(req, &ep->queue, queue) { - if (&req->usb_req == _req) + list_for_each_entry(tmp, &ep->queue, queue) { + if (&tmp->usb_req == _req) { + req = tmp; break; + } } - if (&req->usb_req != _req) { + if (!req) { spin_unlock_irqrestore(&bdc->lock, flags); dev_err(bdc->dev, "usb_req !=req n"); return -EINVAL; -- 2.25.1