Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3584672pxp; Tue, 8 Mar 2022 18:05:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwG1K5NRt1ZEt1SLfcFnHSf+OkYrKPl5beoodM4FiHnRZcnUW+hLueRpkZwp3g/mDTMtDKE X-Received: by 2002:aa7:8585:0:b0:4f6:f528:2e02 with SMTP id w5-20020aa78585000000b004f6f5282e02mr14466780pfn.76.1646791553186; Tue, 08 Mar 2022 18:05:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646791553; cv=none; d=google.com; s=arc-20160816; b=D6Ub6gr14C/8JXjh7YIGOJ47eTw25y9kh5UPDzg3kPIblAMFTxRyhm6R+/1ZBuzCGR cPrhHDPtT4SkwnidlHerSBzAkWry1jz1YAgVATFnvZgCIc8oAMiD6HdBJLZOEmylobDw AbzgRHkZMuA0OjsomvuvTDczFbPB+9QFGiyVg/25IeYuPsBUCJm8fLqnPLjYCUwyMhFu dvz7ixl+PuO58KeQCTr3Eje9rUwyKBexXKVERafIKbRXMXscEXMpVaq6MFhsLVa66zu1 LhGsVgshGZIQI/XbpDcrD8H0mIJVMXk49OqFmi6pO5PDuZ9NkxnnO/k18NVEPRbydXSS d0SA== 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=N8sypLoqqUrLokDZ1BzWM/CJRguZ5x0Xpk1JVIhPD+M=; b=QUlUm+GP48IHLlstJiDFJgdZV0c5eCdnOaWd9U14Dm6V5tmeMB04Wu5543GZKkd0hB 764Q6MOZN4w+Z2EHySjtcHmyYXk2Kw2xdcxF320PFbtKjY0CTOFoox4dmo7UqYmTrX1N 919tAEWZJhp03TGL+rCwDtr/Qon5RScBnAQnKslJ2LiZ1GzQwrwE7r1b5zOgzRrAueo8 sHDiFx9NM6Edi4ZoX778im8x/uaRFYVjFIpTZl5X00+mIK3xXCdI5eB2quK5GW1DryqW FIsMhxOlQzrtVqMy5zI57dsmavJdFFWJ4ACqJZdTwPgMWbDtAXQCB+1H8vpnKQxggmjF yQRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pzSWzeP0; 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 g1-20020a170902868100b0015151ed2e95si582832plo.274.2022.03.08.18.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 18:05:53 -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=pzSWzeP0; 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 27587240DCD; Tue, 8 Mar 2022 16:37:48 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349082AbiCHRVZ (ORCPT + 99 others); Tue, 8 Mar 2022 12:21:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348966AbiCHRU3 (ORCPT ); Tue, 8 Mar 2022 12:20:29 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A5CD5372D; Tue, 8 Mar 2022 09:19:19 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id x5so25369090edd.11; Tue, 08 Mar 2022 09:19:19 -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=N8sypLoqqUrLokDZ1BzWM/CJRguZ5x0Xpk1JVIhPD+M=; b=pzSWzeP0NZJI7823NFDxQfOeimyrLNPWnRxdQ0Q2zZpkwOJ2LxfVRP5kT/iVQkXkYP dJC4nMDHXqSVGosla1Mygiwl7sLIVTX+tGGNMRgeaGdvxUb4tOps1vVtEdMn+yGZ7YKQ jDCm8s401NwC61bRAOzIUso1sQKSPcOxyWze258ctr5oCmD0PKM4gxwvCVD+k2fs7fmQ m//ugy4ckRAT3cxsT4QFESj5lnwUzcFTm3YUaaFdd2sFxPjh+saGaDRbsfCnslazbefa 5PZa+CtTM7BwjhCTfWHlwIZKTaBay2BrcgsioorxDbFOPWApXR9ErdQukCMbUsrY7lA/ 3RKQ== 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=N8sypLoqqUrLokDZ1BzWM/CJRguZ5x0Xpk1JVIhPD+M=; b=MiZeOifNf0lUCoJnAZXwJgNA5SexvFYargHLkd2mPwItTHc3PPfCVOqGZz4cRwK/M+ fGviOGxFGDf+VKPII6sniJxZe9LNtkkYMX2xSzT6qEcDg/2Q6SDqCUbCJuQNND32F38D ROvlBwj9aao0MnSz8HFWAs55XgE6BIU8oZwOgaqsiespKeKGQ5CsrT7KIIoVqOunuSko bGSkRkppZ9vWCDovOll9xVuMnA0mREJIO8t7aHAo5NhZBBGuTGEyKi5nw3jhfHYE1Mae bCLxWZ0Iq16WetND4i3Re6WHVas+/KQKGyQ7MKbV5VQldD8kbqEu3XuF+MhZOxDYgnNl VPgQ== X-Gm-Message-State: AOAM531AKtN9OV7iRJ2NwfdkKkZJDSzLSaEY8kAdBR0eADUuR+NPKxF4 qY3eAopSZzTtgNRVxNt43Hc= X-Received: by 2002:a05:6402:d0d:b0:416:1d69:f23b with SMTP id eb13-20020a0564020d0d00b004161d69f23bmr17205986edb.141.1646759957318; Tue, 08 Mar 2022 09:19:17 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:16 -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 10/26] usb: gadget: udc: mv_udc_core: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:02 +0100 Message-Id: <20220308171818.384491-11-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/mv_udc_core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/mv_udc_core.c b/drivers/usb/gadget/udc/mv_udc_core.c index b6d34dda028b..fdb17d86cd65 100644 --- a/drivers/usb/gadget/udc/mv_udc_core.c +++ b/drivers/usb/gadget/udc/mv_udc_core.c @@ -771,7 +771,7 @@ static void mv_prime_ep(struct mv_ep *ep, struct mv_req *req) static int mv_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct mv_ep *ep = container_of(_ep, struct mv_ep, ep); - struct mv_req *req; + struct mv_req *req = NULL, *iter; struct mv_udc *udc = ep->udc; unsigned long flags; int stopped, ret = 0; @@ -793,11 +793,13 @@ static int mv_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]); /* 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) { ret = -EINVAL; goto out; } -- 2.25.1