Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3528175pxp; Tue, 8 Mar 2022 16:41:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzM1QD2XsF6W7YlbWpgA2C8fo0aUI6OyEtuUffUncteP1WqkEfbMRUCei+QNOeIKC0W/aT6 X-Received: by 2002:a62:b410:0:b0:4f7:b6a:924f with SMTP id h16-20020a62b410000000b004f70b6a924fmr10857366pfn.62.1646786493718; Tue, 08 Mar 2022 16:41:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646786493; cv=none; d=google.com; s=arc-20160816; b=JsA36DO4nYL9gf/s7sQ6G+usrRXi7swG4h0UhULvXRhg+HdXxhMmVhgRNip6wp+7o4 vKmiDUiyRNZH3BCJDo2wG1mO69EVUr3J74cKN+9SKieNS2zpvbecNbI9c5cpcTrroPED tvcG+eg8K0tHFs3wPSSX1T/y0ySoGLddTfY65aFpxQUcIhHdaRJlKOLNPoFhlyoV/7S3 HREPcltTGyLTq90laMzMhG3IjTl8ppZABPOybizxWLevux+Jknog18Wh6MJouDH/LOhS ucEMxhrEzC2UJMna2Z2iyZHSAxwOT4WGJBIdYMp293AO6AReWTpoEcEFlKiYEegWrXar PU1w== 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=vIp5MlXygySPCwO7mdoHIhdgzDhIp7fZD6S7LhPAPYQ=; b=J7vYtDgNdUwVysohMK5aXIKAK+PnS1is3iNPjSMPi6iqP0ROlSNYFtsP6hZ9okWrve M6tB9bZtZ2oPZG7NIedkDCMSTJZLlCypPEpRAcjcRzSD+6cOpHkXni6nblk9waRsS0lj Cv4QnsSUY1fYG4hkCVKleEjvNu/oEEHBpqdFddQ79hLqn9KjVEprh5ZP06MoLabBQtgM Xw7XdMrHtbfC+cEb0HQ83HsPRBDsODmeJJ3jtGCCTcUnqMqXsoJ+ZG0xbkGKiGa6rXNx o8vagZua6v7+tglGdQIKBLHZ4CMXFZbqAuOUig+V6E8j9VEF46l+1uDxtDz+DymGHbew gcHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WlNGKUPa; 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 r1-20020a63fc41000000b003746edc249csi364895pgk.393.2022.03.08.16.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 16:41:33 -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=WlNGKUPa; 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 6D02412D92C; Tue, 8 Mar 2022 15:55:56 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349038AbiCHRV6 (ORCPT + 99 others); Tue, 8 Mar 2022 12:21:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348993AbiCHRUk (ORCPT ); Tue, 8 Mar 2022 12:20:40 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EB9B53B76; Tue, 8 Mar 2022 09:19:33 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id bi12so27680032ejb.3; Tue, 08 Mar 2022 09:19:33 -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=vIp5MlXygySPCwO7mdoHIhdgzDhIp7fZD6S7LhPAPYQ=; b=WlNGKUPak1CvnPMtyNgNi2hWe8vUySX3SFUz0MyTpUDSLIpJ3OXgXlHe5Z1opA92YF xXAAHkz8XTizVzSD0t1S26O3Sfk/aV7F2fGP/YMUxOdylQjf+MpRz9OgNgz9QOjAuHcA u4WsKLMoKmjOJ5ObJpVPRRAhDxICwxssyIvje4f5+I6GYkRoUAWDamD+ZAvAmXuAdNmg qAX3AHnvXyq5C8B9+4jLXMjdGcDSSHhXAJxekiGbM1vfdW2TnlBf3o5M91Bg1POzmYjh lFFDfc+bdmvWomVlY0cXSAPO8iyPyqQwhjvQBJw2OTQ3MfrxV2pWHcixqALu0MaHvnPY Gy/w== 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=vIp5MlXygySPCwO7mdoHIhdgzDhIp7fZD6S7LhPAPYQ=; b=mvxAaTNrh295U0aC6vTOEEhFQZowqNXfTeleX+mz0nDXncdyVuEHbBCDI1vne0yqKV oDHRl3v0w+x4iQrzhMyoJMwYNM6ONbaGDGuhkNN8BF5CWnwVK2lsgrjM7MhDvSwUIIhz WBp7mhXid9q8fjjIOcPd8ejANaBCZLSUnxaHchczXtafkqURZYRs/0f68Zp208jCbyNh 2Qt3ixnnQkUuvj0EROYq0twcPHORQOkONw6e2i08TxhHI1XCFCXMGM5apPNu/AvV3Mjg ZvDdLMmOZQgV2/WelT2CY90+FtY22eDDDgPGOmMA4d4qqnKAnqs7SoBDbw5QFDXjdDkI CYqg== X-Gm-Message-State: AOAM5336Xn/Vx2ki2xBW06kq9JWEJnTZAmBJUuZ26m+msCMXhA4CfN6L cIa5sEohvshvYqIl7Wr2NDc= X-Received: by 2002:a17:907:2d11:b0:6da:924b:748f with SMTP id gs17-20020a1709072d1100b006da924b748fmr13877030ejc.584.1646759971897; Tue, 08 Mar 2022 09:19:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:31 -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 20/26] usb: gadget: tegra-xudc: remove using list iterator after loop body as a ptr Date: Tue, 8 Mar 2022 18:18:12 +0100 Message-Id: <20220308171818.384491-21-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 does not contain the expected element, the value of 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 list_for_each_entry() loop. In preparation to limiting scope of a list iterator to the list traversal loop, use a dedicated pointer to point to the found element [1]. Determining if an element was found is then simply checking if the pointer is != NULL instead of using the potentially bogus pointer. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/tegra-xudc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c index 43f1b0d461c1..1ad616d81c96 100644 --- a/drivers/usb/gadget/udc/tegra-xudc.c +++ b/drivers/usb/gadget/udc/tegra-xudc.c @@ -1413,18 +1413,20 @@ __tegra_xudc_ep_dequeue(struct tegra_xudc_ep *ep, struct tegra_xudc_request *req) { struct tegra_xudc *xudc = ep->xudc; - struct tegra_xudc_request *r; + struct tegra_xudc_request *r = NULL, *iter; struct tegra_xudc_trb *deq_trb; bool busy, kick_queue = false; int ret = 0; /* Make sure the request is actually queued to this endpoint. */ - list_for_each_entry(r, &ep->queue, list) { - if (r == req) - break; + list_for_each_entry(iter, &ep->queue, list) { + if (iter != req) + continue; + r = iter; + break; } - if (r != req) + if (!r) return -EINVAL; /* Request hasn't been queued in the transfer ring yet. */ -- 2.25.1