From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 302F1C433EF for ; Thu, 7 Apr 2022 10:32:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=idymtctPSZ1dWtIrBCdKFvUyXHfQgUIT+DSQMJhfWEM=; b=YZvvkEgMWbUc1U Ctn6fb2KiprRNwoAbBgZsDQ/2YeYbUq9ZIBQPgWc+BSd+MYavHWRSODGECVfzUMrn9LLoAnzSU+Ye xMz/4dNw7dx8lcs/75mRqhoRrlr1jhBvji3Ds0odSJnFcDYOI69CCsfM0S7AEe/HXw6B61SDtOMvZ 6k9M137rnksOvG7SjOSWnqPpzXj5YBr+JHzhxJ1A3074wC7npiY7OBy+cI3wm3F87dylYUlJNC02Z 3ruzQELB85fu4Ze0tEX6vz6Fbf9f33u9UnpbQkJZXSQy5Lo5kb/MPZECGUlGNXn2AQSpBj9NhhsVl mgxnjYjOrcUomkiTH6dg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncPQW-00BEVx-VC; Thu, 07 Apr 2022 10:31:45 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncPPv-00BE9N-67 for linux-arm-kernel@lists.infradead.org; Thu, 07 Apr 2022 10:31:08 +0000 Received: by mail-ej1-x631.google.com with SMTP id p15so9867568ejc.7 for ; Thu, 07 Apr 2022 03:31:04 -0700 (PDT) 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=kT9lxrok+SOZ0lJZngMY/3t48p6ivac6h4GBagGgqlA=; b=A8dgIRU7XpwGn8L/TWG7eFAfHkVAzizRPgoC1D4gc2OIpAMDpQJiTRoz9/IZCjJOM9 0s/42Xr99tqQ/JiR7ikZbfNGvGTjsSHBNU0AYR/pK/X2p6qv+xnvCz5faMoZxi90/IKT PNc0mh3GTFWBDQq/CMrWD0tfMR9PZS5MU6bXydxhfUYbVNe/A45xXvJgVLM0d4Ko+mBZ zEwllUgvuEavEaIEI448YgPIJ4PuwL86Fv8WZf4DJCkQAfkD6Ngv7DCP695sV2rZt6D+ o3zzSLnoDfg2cEkyeyKGITs5rnEClHAm1GR6V9FxE6OPBIgGTU//ptm4fVdBqItJvn9G MWLA== 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=kT9lxrok+SOZ0lJZngMY/3t48p6ivac6h4GBagGgqlA=; b=ToA7ZDb9hPevzVdZZ+qeUzsVcOpG1BiDkGWJT5XWm915gACirbyHB4nhote4Nw5X8L h+g/Wr+/5yE+IcvwmVpfNyHDP50pvPWYtULDlJtootvoMpbGS4w3aDajjK3Lic0eVvBg zk1qQpKbXcSLBKXlopRLao35ElSb5HGC2UjiDsPjzBrazN9s3NjUuaHKc565TtgObCFZ S0/yHgkFjQyw5iMUFi1ZNNfq0eEl0+25yG5nQpHWbb0SaxFUS1eVPWmc7yQrFA1z0b/z 5uEMcxvDl6FGzTuyEpeLCFJRXhA1d4IHcLwlQSJuWOSZIsfHwmgArTUnaq7lYB6FZndA c6cA== X-Gm-Message-State: AOAM530sk821eKgkCHRpQGel55zkD3oT1g0+guRPn4yfeDPVwydqRiTl D2vCShi4NxBenUtmrxf5jWo= X-Google-Smtp-Source: ABdhPJz1ozEcGcfvbMMbR7f3V/Sq2iRBo4hnJMmtYdRPitfh6Ug/fwJ4nnyfng/IyzCFUa3t6H3CwQ== X-Received: by 2002:a17:906:4787:b0:6e1:409f:8deb with SMTP id cw7-20020a170906478700b006e1409f8debmr12629244ejc.80.1649327463446; Thu, 07 Apr 2022 03:31:03 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id c5-20020a170906d18500b006ce371f09d4sm7413573ejz.57.2022.04.07.03.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 03:31:03 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Cc: Jakub Kicinski , Paolo Abeni , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , Lars Povlsen , Steen Hegelund , UNGLinuxDriver@microchip.com, Ariel Elior , Manish Chopra , Edward Cree , Martin Habets , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Jiri Pirko , Casper Andersson , Bjarni Jonasson , Jakob Koschel , Colin Ian King , Michael Walle , Christophe JAILLET , Arnd Bergmann , Eric Dumazet , Di Zhu , Xu Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH net-next 02/15] net: dsa: sja1105: Remove usage of iterator for list_add() after loop Date: Thu, 7 Apr 2022 12:28:47 +0200 Message-Id: <20220407102900.3086255-3-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407102900.3086255-1-jakobkoschel@gmail.com> References: <20220407102900.3086255-1-jakobkoschel@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220407_033107_295699_2FED587F X-CRM114-Status: GOOD ( 17.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In preparation to limit the scope of a list iterator to the list traversal loop, use a dedicated pointer to point to the found element [1]. Before, the code implicitly used the head when no element was found when using &pos->list. Since the new variable is only set if an element was found, the list_add() is performed within the loop and only done after the loop if it is done on the list head directly. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- drivers/net/dsa/sja1105/sja1105_vl.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_vl.c b/drivers/net/dsa/sja1105/sja1105_vl.c index b7e95d60a6e4..cfcae4d19eef 100644 --- a/drivers/net/dsa/sja1105/sja1105_vl.c +++ b/drivers/net/dsa/sja1105/sja1105_vl.c @@ -27,20 +27,24 @@ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, if (list_empty(&gating_cfg->entries)) { list_add(&e->list, &gating_cfg->entries); } else { - struct sja1105_gate_entry *p; + struct sja1105_gate_entry *p = NULL, *iter; - list_for_each_entry(p, &gating_cfg->entries, list) { - if (p->interval == e->interval) { + list_for_each_entry(iter, &gating_cfg->entries, list) { + if (iter->interval == e->interval) { NL_SET_ERR_MSG_MOD(extack, "Gate conflict"); rc = -EBUSY; goto err; } - if (e->interval < p->interval) + if (e->interval < iter->interval) { + p = iter; + list_add(&e->list, iter->list.prev); break; + } } - list_add(&e->list, p->list.prev); + if (!p) + list_add(&e->list, gating_cfg->entries.prev); } gating_cfg->num_entries++; -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel