Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1768793pxp; Mon, 7 Mar 2022 01:52:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvpzfwLA10DRrYvBHSkNVflA8haJUppJC3R8Yv5pEzcBGMlk71MsY29vxOszTXiCGvYnDc X-Received: by 2002:a17:906:1be1:b0:6ce:b0a8:17d with SMTP id t1-20020a1709061be100b006ceb0a8017dmr8087601ejg.413.1646646731407; Mon, 07 Mar 2022 01:52:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646646731; cv=none; d=google.com; s=arc-20160816; b=trIB6dM8XTauAakzWaEzWHrFF3NCQ0syodAAS91YgPAMaDSxb2DandhNuFOQr/Qy+R Jy9VmeNAkUjRq7ClTljN+fNMoiahOUWDd0XxJNxzaykdNz4aaLtNHGauVS7WzjHcaN8W BNQOvP74gvHAS31Xy36ekZoXVI+oMDl3+IyU1ZWNm3D1nTkSbbKBmCAfUZjzx95TuqsT IOzWYaBzsSWwnGPUwCziz+txLl5ryrRpPUiwRYyhsCs/RHfJUEs6KZhKtvuZJ6hCuHVk pp1Cl/Uo8pi7d/bVteVx5Ki8c6zk+nHsCi4wdR/R0+wRCrSWjNKCI82QYasC3etRzSt6 i+mA== 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=3MEN8BkVwGONO6rf4oHEkv2XnGVYH4Y2hOyHB5gTgdc=; b=KzIqNAjNhRCLeDT4ddQ9dqaJhOY+0zGiG5nDYA8WtGgWCTGjk9AYNr9eiC3MhesZJ0 5rxVWaLKo2MkNkOV/R9QDafMba6AllxXbiV5Mv0ckO2XL3t90n2PkxOj4f21Kk2utrmA PBjMw3dX2M5Az0NZy6IWnWMOGeBKSGSi5taDY+/+432zCWQRr3N9kgxkHiae9PbPFs93 /2K+1K32cNUUkFLPuJQQIxFACQJ3dvz7BJ7aggnQ/yize3z7pteHKllSbFmMAmslk8I8 uFmju0g77oM6ZsPNn3rFvQiMNCwqksdIOTQQsNRUVF6xQUCoap4nkUQHaXHYwlz09zMo z/VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Lb6bciyg; 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 e23-20020a056402149700b004160cb9dd94si5403513edv.542.2022.03.07.01.51.48; Mon, 07 Mar 2022 01:52:11 -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=Lb6bciyg; 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 S234069AbiCFRw1 (ORCPT + 99 others); Sun, 6 Mar 2022 12:52:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234007AbiCFRwP (ORCPT ); Sun, 6 Mar 2022 12:52:15 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E63283ED05; Sun, 6 Mar 2022 09:51:20 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id bg10so27492254ejb.4; Sun, 06 Mar 2022 09:51:20 -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=3MEN8BkVwGONO6rf4oHEkv2XnGVYH4Y2hOyHB5gTgdc=; b=Lb6bciygqlIU9k8Og7P0lKRcEwndfuccYEAwLF0g5QHqH+NRevi1EaoIFKgRzLK4X8 NBQZvnfouGvDLv8lezrBxCOWJlkspHv0xdda4CexewXs4zu9l694VKE72HlAm7n3Xyv/ /4D9/AbmQUt7G0bAhDNJ3q13hGsn60qTe/Ur+yZxrbV2/CX/WHc6vvCM+W4ve5lGQgk7 ivpc3cnTt6ltzX2FaTIBFhyaJrZ2YxGg9eqYVcPs8eybPVatlrVTXcdLrY6Hl2xuT/n4 5E+1mnXyvt6PZowXxwrXwAyspgz4YlLzsqrjrAwoqIorYHvV2Xuk6kOHkJr/zsJ5Q86E h+0Q== 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=3MEN8BkVwGONO6rf4oHEkv2XnGVYH4Y2hOyHB5gTgdc=; b=eyuWTIXuGZLAadR/97jaLGJMlgxh4DYu4YRX7LMRc5us42GC7FY10jv9ruIMoG/7UV WHpTnmZgBATvixzQSNQt7u4SYoifqtVDGorEoEqtAm34opBtHqD3Fl78SpsPnu5ROr3K Q3iHwtTgiZPSMmWFWXdO7nMUv0uqZjwgGdbzLuuVOHrvJTe2YqV2rIWuEsDRrHqbqaoR L2izdTCViycGRyLyP5j0ipChIhkFrBaPLmHx5Tfo4GT8B7hs73wxPWePqsb5OEzD0zj9 FfzSs8Zb6xCRfKFjqxP7QAY/q9GTDPl8Mm483tD6kJDtebp6W3a/o84XYOVjCpa12pjq wGRg== X-Gm-Message-State: AOAM531dWioTcOdTW0jI1oJx2uWXmZygCG/zpX45RlFG2tg9/G8Ju3jp OK9dIg4HMI1vW4xi5744p+s= X-Received: by 2002:a17:906:66cb:b0:6cf:e4f7:9504 with SMTP id k11-20020a17090666cb00b006cfe4f79504mr6692389ejp.142.1646589079445; Sun, 06 Mar 2022 09:51:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51: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 08/26] usb: gadget: lpc32xx_udc: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:16 +0100 Message-Id: <20220306175034.3084609-9-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/lpc32xx_udc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c index a25d01c89564..fbb235b1f23f 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, *tmp; 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) + list_for_each_entry(tmp, &ep->queue, queue) { + if (&tmp->req == _req) { + req = tmp; break; + } } - if (&req->req != _req) { + if (!req) { spin_unlock_irqrestore(&ep->udc->lock, flags); return -EINVAL; } -- 2.25.1