From patchwork Tue Mar 8 17:17:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 550062 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 D2C0AC4332F for ; Tue, 8 Mar 2022 17:19:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348936AbiCHRUl (ORCPT ); Tue, 8 Mar 2022 12:20:41 -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-Google-Smtp-Source: ABdhPJw15Ja5rX4M5jLmfuwddHWLBmlT9d5NTtLN1JZhmh7XvUj+FntdT2S5+9Vf7v06LvsGfvzMvw== 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 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/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; }