Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3560189pxp; Tue, 8 Mar 2022 17:28:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzyKnDvaO943UuObrh2k+XL4QIkg2FKsJWBYIbl7c0WxI6GZ4lD4P9ZaNPk2CWGjWf0n0I X-Received: by 2002:a17:902:c40e:b0:151:a83a:540c with SMTP id k14-20020a170902c40e00b00151a83a540cmr20466792plk.10.1646789295146; Tue, 08 Mar 2022 17:28:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646789295; cv=none; d=google.com; s=arc-20160816; b=Qvil13YeHNGhItyHkKDMoGb9ETEwacXhhbqEkeHMOLKA4zZwpTRLkNG0E2f0nXKMLW VDhgWLv51NzTV4NjtD5JhWlW05CYFyBQWKAQraaUVdyd+ytu3nClV9xYGeSFZDnvHLDk HTQTmeMoUjKbwy34FBnPt8N3wLVvc62g/Uf5sl0k0czRQYU9XAdpgK+5riRhl6DwLz/O mzZfUBtq2XFcugTlMmOSmdIhzB54T3xhi3TAAz2uZfU9ZUJIjoNpPU4GwRR+5xHVEoQ9 ZOc2dZ/dQv2mhZR/u9Mq/PRhS7rtbv8poeCovW/FSn8sOty09bUYXCIxgWJ8Gygd/W9I WTyg== 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=u9SG1/Vum4zcALdcRrS/dZdkcV9xg98RrAHqRdSRgAY=; b=MEKd4b2WizKXABEdBK/FCMXxOjl84IYlg55aYiyt2Tt6KkHF0C81I/fJsa5VZbMOPI ityQcN2zhLAFbbdNt37LLGwFgABT1an+8GK31qQxdDrvyGnRWscJ1BivFWgbbDkmBIEc JC72o27QNiHxLJMXKdjXkTDJ8+ZZqYjCkQYv7dUwaSMs43mW4Y0hFwuizsybWwmuIYez IZDrwoc8KAVRO9Esp6H1zAGc9l3vBW/cjDfkYNAllnb3Do+bVxAsOv5rAK06/zMN0lIL js0dy40OwuVkf1Sg1dxb5Cwgz1mXr7tlu/wWEAJut2wXzvfjC2+FxOSiw1d4EXJ65qLe zcww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JofGUORG; 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 q85-20020a632a58000000b00380228791e0si474658pgq.40.2022.03.08.17.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 17:28:15 -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=JofGUORG; 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 9EEA831DFD; Tue, 8 Mar 2022 16:17:02 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233085AbiCHRWZ (ORCPT + 99 others); Tue, 8 Mar 2022 12:22:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348978AbiCHRUr (ORCPT ); Tue, 8 Mar 2022 12:20:47 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0FDD5419A; Tue, 8 Mar 2022 09:19:37 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id q17so25426443edd.4; Tue, 08 Mar 2022 09:19:37 -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=u9SG1/Vum4zcALdcRrS/dZdkcV9xg98RrAHqRdSRgAY=; b=JofGUORGmECmPMRyfeCgpacdZGtX8kTCkXo1V9bqn0kmDI7cVnjjfrga0H5AcMGLTx 3+KEsNvj9PwC5EhLqCWMlFkoNLtz12sZezQDxC4mGa3GqGqAexEYowu8u5/dY3CKZG7M OqkQmiuT/vz4LD9Dak0Vu7gJKjbf90cJXK7hfwLBigxL6sP/O4ZD4WsxgkMOavQ3I+MW r69d7ujJy48OXAAQ7f9vIGu3HKUynY9irfc4+11KDQziuecxQHBvcOOgzYYJHd97qlQO ZwIs6nfSLBFV3f4XPag+WOejrgaDNhYl54YqPoilSOmRvzZCx9Fh53IUCuCokeJGOklI x5DA== 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=u9SG1/Vum4zcALdcRrS/dZdkcV9xg98RrAHqRdSRgAY=; b=I64fz82NZXSjNvhK6x1HUQwvNM0kMXG97yDfxhrnRpjiKRZz9N6tRXMj8fbSmf/iKN H/Efm13Zo0fM4SHbMpnUxh0p9c58VECVGPTMYoAsMp/XoMUNsjnoQca7SOgKcJ/V0fMg 88Alo3LWP4WvxkUFuGv1F2RUqG4DBqu/+iXcnFyIRnLderuMdkFNEzXFSqdQryWD7aFk RkAiBI6GE4CaVf0HxkXy+uDfRq1PBAlJOB1vYUT1ZjQAhJQme2eXqxngwaunJKvElIwM WgfWa6b8Uex1yEmJisEoyxZ+54Cu/VVi0Nr567cYjWnhO96/xSjPhhjxG8mKJrC1egHS QeNA== X-Gm-Message-State: AOAM532SnERl79GUVf6cNakeVwrlHgPdnyaitlS1g/yAUrKJODkwQayz D2qMRmiE5ArUDtgeCw/CApA= X-Received: by 2002:a05:6402:5189:b0:416:63fe:fc6d with SMTP id q9-20020a056402518900b0041663fefc6dmr6718640edd.120.1646759976213; Tue, 08 Mar 2022 09:19:36 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:35 -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 23/26] usb: gadget: composite: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:15 +0100 Message-Id: <20220308171818.384491-24-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 To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/composite.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 4f7e789c3e07..2eaeaae96759 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -863,24 +863,25 @@ static int set_config(struct usb_composite_dev *cdev, const struct usb_ctrlrequest *ctrl, unsigned number) { struct usb_gadget *gadget = cdev->gadget; - struct usb_configuration *c = NULL; + struct usb_configuration *c = NULL, *iter; int result = -EINVAL; unsigned power = gadget_is_otg(gadget) ? 8 : 100; int tmp; if (number) { - list_for_each_entry(c, &cdev->configs, list) { - if (c->bConfigurationValue == number) { - /* - * We disable the FDs of the previous - * configuration only if the new configuration - * is a valid one - */ - if (cdev->config) - reset_config(cdev); - result = 0; - break; - } + list_for_each_entry(iter, &cdev->configs, list) { + if (iter->bConfigurationValue != number) + continue; + /* + * We disable the FDs of the previous + * configuration only if the new configuration + * is a valid one + */ + if (cdev->config) + reset_config(cdev); + c = iter; + result = 0; + break; } if (result < 0) goto done; -- 2.25.1