Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3570068pxp; Tue, 8 Mar 2022 17:43:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJya2xkk91t5qNy+FvbWhV/6MkAh7vwvxadGL1LNCOLbBuLkKaXq77UDzxt43lwifc4jineh X-Received: by 2002:a63:4814:0:b0:36d:87fb:f1ed with SMTP id v20-20020a634814000000b0036d87fbf1edmr16362083pga.594.1646790223901; Tue, 08 Mar 2022 17:43:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646790223; cv=none; d=google.com; s=arc-20160816; b=PCbCHNvai37+NpnqSjLEcY0nt1lb5m+JVWhSbpOap0mJq+Unp41zqdKz1JhvhZ7V9l sYfluqYMpztK2rInNEnwTiz8Ui35Ji4kl78iJn2ciMhfhtLSBMKZRcetk194ZeNciMs5 7vGfGZRfE81r6SyWd+1XMdZv3M5CfulVX0nCuIAcCDD464Ssjdw58Mjn/GVzyF1AdIv9 X73/EGpSv0X+IXacFobd4v8BllB774Teyz73cGhM+0+gZMQVzS19Jyit11LbH+BW9dE/ FS8j5YSK3YsEMSnMuPNqYhU4HJiBYPu8at/qZXwVwQGLuJpL/8s2QnQVeEQEWi4d4L/z dglQ== 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=jnMNicDFLPFYIm4a2kBPICTpJsAe2MnYZ9lJwoywQGA=; b=ULfK5L6bltwcfYa50JVty4tB0Wxt5aCWL3MdlR3JXsaczHpTDDqO6C7jt2w0Ca/7Gd QTE18YGtOtHxn9Ocw4PQj679+/TLZXs/NdweG1apXwIJkhL1RRBG/5RcvAmQBUueuh/Q 2oiWCyIh86Nix0Upo5ra5CH4HEtd5HIMKPzuupOQ2TWyVH+ZGzn47CIllUmAwb6PlQkx rflEirgBI8Z22rU3QjUeSNoovWAcJccaKvEQU1/ona7nyhD+aLhR9nu2R+jGIkOK5in5 BLyr2kvZzPB7TppeqG2iRj/1Hv16wDRteeZUFjSm8jqmXH2aw+BcOItUIR4bPo3pw9sX YSzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GaQjF3wq; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id m12-20020a170902db0c00b00151ef4e4da1si603263plx.123.2022.03.08.17.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 17:43:43 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GaQjF3wq; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 BD822ECB1A; Tue, 8 Mar 2022 16:22:40 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348896AbiCHRUv (ORCPT + 99 others); Tue, 8 Mar 2022 12:20:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348952AbiCHRU0 (ORCPT ); Tue, 8 Mar 2022 12:20:26 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C25AE541A9; Tue, 8 Mar 2022 09:19:11 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id dr20so40692814ejc.6; Tue, 08 Mar 2022 09:19:11 -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=jnMNicDFLPFYIm4a2kBPICTpJsAe2MnYZ9lJwoywQGA=; b=GaQjF3wqn4GDvugYvXEA1XjE+wgTl5NlMnFteV0S7o8N7s5d9UTG+9G5jeFiOMnWkT RskkhtsXFNvk1/H3WcrOojKAhWAwh7HglW+3DJjyy5rNrV7Po/lXl9X6ROJmiORWzN11 xL9h3DFcuURGNiGngica/PJxipY5z5BlDfcX3q/jxcka8ynC80NjVV0MwUWLEr1K1tGX iCS3j6syn+9+Uw4wIM5ljO+L9Nyu++x96ttz0xHnB19nsgROSsJE4gyQGDYgLLYCtb6X qohOA1Z0xzQLO/lV79wzNO9B6Yz6Tyyc8rtIVTUE9ga87i7C2gcvhGaCsbd3r5+R1895 WZFQ== 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=jnMNicDFLPFYIm4a2kBPICTpJsAe2MnYZ9lJwoywQGA=; b=TCiC7njCJWlvOMFnXe2/uLjW3EiNzBnh2l8uUAc7zdB/OG1xYy82paT+22vp2DZ7HF w2GOQJpT4YeV8BDpCFQgB7w3Ykz6oL9lWaPhcSTWL5QfL0Q9NwFm+rUA4iNC9LIQGb5A gSIKbUjILqzR4/06hzTfr+EMUMz4/L1vAGbtCbZG2Pb90WYCqrLo31f6YSwuzMmJZ+wK 8rtIXPSw3gp1xRT9PoxcluXHNknbWRU0k+qqNkgvnKYMKnRSKLMi6l61xp6CJZ7gQ3XA U1nGPfib5H8mpwGpLJF1zn519w7RAnw9kyMbtC74uGLUa5T+Lbz4dDrfNOHu34ys2buI nzfg== X-Gm-Message-State: AOAM533F4t5Vi6dGbM99QFf+jxA0xOICcGeoGl3V4NE3F+5Uo7Z+xFp0 4Nqj+x9vb8RiXYOLwBu1qmw= X-Received: by 2002:a17:907:168a:b0:6da:9167:47dc with SMTP id hc10-20020a170907168a00b006da916747dcmr14225921ejc.126.1646759950264; Tue, 08 Mar 2022 09:19:10 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:09 -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 04/26] usb: gadget: udc: pxa25x: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:17:56 +0100 Message-Id: <20220308171818.384491-5-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/pxa25x_udc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/pxa25x_udc.c b/drivers/usb/gadget/udc/pxa25x_udc.c index b38747fd3bb0..6c414c99d01c 100644 --- a/drivers/usb/gadget/udc/pxa25x_udc.c +++ b/drivers/usb/gadget/udc/pxa25x_udc.c @@ -966,7 +966,8 @@ static void nuke(struct pxa25x_ep *ep, int status) static int pxa25x_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct pxa25x_ep *ep; - struct pxa25x_request *req; + struct pxa25x_request *req = NULL; + struct pxa25x_request *iter; unsigned long flags; ep = container_of(_ep, struct pxa25x_ep, ep); @@ -976,11 +977,13 @@ static int pxa25x_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) local_irq_save(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) { local_irq_restore(flags); return -EINVAL; } -- 2.25.1