Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp820805pxb; Tue, 12 Apr 2022 14:22:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDOMWf1456Xd0rpy97WCwvc/QVo4UWl1Gwklwe8heYBr9M87JFkiUSRcKxFiz9O0XfJvZz X-Received: by 2002:a63:b542:0:b0:399:40fd:3ac3 with SMTP id u2-20020a63b542000000b0039940fd3ac3mr31873037pgo.564.1649798569818; Tue, 12 Apr 2022 14:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649798569; cv=none; d=google.com; s=arc-20160816; b=an5WbCEgqO+6nwfQhwD3OBDby85YIVsWXZk90nUUghjXiH5nLidz9XGaJQiyIl6cQw vOkRdlnyi9gPp9TKvBnzuNeHC9c7fqIBYy3DOm5Vc518Ig2ht8PjZQTSdPJZ07386Hwo fYH6U7IfCljelBEYcg5xHgd21iDiDoBEd05ZF4F8cZYexsuG9JPTaP/nJfbo1ktNR+JB m6haHAd32uJy7/L5TFwgur21WpHDBSlenVzqi+yA3LGYJ4PAu9VW2hfgN0bMAMqsqV2f 3jK+61z+FjIyOZOjWws2VJ3L7uuPV7Yda98VvH/bEOU5zJjq79sZMQeGUwCPPNDmsrgC +UcA== 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=woYPht1iAY/ITrpUe+WmESGMoM6pZPj3PA3p1Q9RO1s=; b=Rgx4slf8pcQX4OOOOn2aD5Yhkkt1y4eODXyhZ3wqHVeB9lcmpBamUMIJ48lfbkL24F LuhS5Q7LMz1qC1MDZ9UWqeKs9c/igesrKOVcBDsRP4YxhHujDP9GNOhin/47+4+vkA6q ydZJfW5W9smcMlBWShi4mpafIUm8utO0gHZFq1vKMTxeXh1lTWS1wTBC7XTXtotsIqez B5o0SH/OhHEFLbGfxRayFNdRVOyQNrHQVqlpktSXMwjAQFpDi2jHfONk67shz0JJ6sFD +JStWmHsPZawVnrcvg7RA+I12Z8sYzifwXz2woIpGu64HY5UM/06HHgEbdR2bPhSP7wr v9hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="GLAEL/Wn"; 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 t16-20020a170902e85000b00153b2d1651fsi13556232plg.295.2022.04.12.14.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 14:22:49 -0700 (PDT) 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="GLAEL/Wn"; 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 57B0F10DA57; Tue, 12 Apr 2022 13:34:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347885AbiDLMGe (ORCPT + 99 others); Tue, 12 Apr 2022 08:06:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351819AbiDLMCn (ORCPT ); Tue, 12 Apr 2022 08:02:43 -0400 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 35D287DA89; Tue, 12 Apr 2022 03:59:13 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id l7so31105884ejn.2; Tue, 12 Apr 2022 03:59:13 -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=woYPht1iAY/ITrpUe+WmESGMoM6pZPj3PA3p1Q9RO1s=; b=GLAEL/Wnep8C6HgHiZIeQleRfVNhSS+4/IX8MmJQcWytrQ4gxe72994e2BvJApV3Gh +mNin1xpG/WQ/D6ovz8BvFIqNOhFfWp/fZ9cgSKQ6eTUvGI8WcXlhs4/GKGrhpXEsGcl rxCeEihBgqEqVzLatl4dCY8obePJoW+H0b4qyhgf1gmsVkm6qKM8NMjq0JX/A60ZN6UD hBFrqYvcL+vhI34TqDRks6xnYoKdpyCqNKlPKc+msvi2JB4Ux9bNUCcuj2rklCJkH1A7 ++xTwBP8+uSMDY4K8o4JFoOrMZefXLk5jdDqQ80MG0AM7Vz/QbJOlik0jeja5ONs+AdT fHGA== 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=woYPht1iAY/ITrpUe+WmESGMoM6pZPj3PA3p1Q9RO1s=; b=WCWlT/kM5P5OgiaBKycKJxJvd3BmGZJ6qPEETKc+Df80eu7bpw7a4hTwpPbfyz9uQL jLWQiQojv6Jtrnx8s7p3u9wxxOR/j4WJwsjqlHEbcT4+Z0vJRnrjcPb4ZGqRPSA1tzWN 17bACKIJl46aroIN/8l9I1I9ElBiiCdEnmPUX0L+7BxSK7dKSnq4j+Q9IEyAIWExFyvA GsuJ3HdoTZ49rQgvc9D9NQCJ2xSe/dUwKjAFFDf95tsTHfgKPPLs1tTKY4BahnqTCjFs rx+1PUhIpGN+SQbLDVenYFewvSGvrVS9BVXFvKljJqyvvAvb9S4pGpN6Ecgn4X9Jl6Pu +v+Q== X-Gm-Message-State: AOAM531b6UHsK46X666r/hiif2eBdUHJQt76RjNQnylloEiahfqxscy5 QtDvjlCWt41i50DFx+wknWQ= X-Received: by 2002:a17:906:1603:b0:6ce:362:c938 with SMTP id m3-20020a170906160300b006ce0362c938mr34468664ejd.253.1649761151541; Tue, 12 Apr 2022 03:59:11 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id f1-20020a056402194100b00416b174987asm16986370edz.35.2022.04.12.03.59.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:59:11 -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 , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Casper Andersson , Jakob Koschel , Colin Ian King , Arnd Bergmann , Michael Walle , Christophe JAILLET , Eric Dumazet , Xu Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, bpf@vger.kernel.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH net-next v2 15/18] net: netcp: Remove usage of list iterator for list_add() after loop body Date: Tue, 12 Apr 2022 12:58:27 +0200 Message-Id: <20220412105830.3495846-16-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220412105830.3495846-1-jakobkoschel@gmail.com> References: <20220412105830.3495846-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 In preparation to limit the scope of a list iterator to the list traversal loop, use a dedicated pointer pointing to the location where the element should be inserted [1]. Before, the code implicitly used the head when no element was found when using &next->list. The new 'pos' variable is set to the list head by default and overwritten if the list exits early, marking the insertion point for list_add(). Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- drivers/net/ethernet/ti/netcp_core.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c index 16507bff652a..f25104b5a31b 100644 --- a/drivers/net/ethernet/ti/netcp_core.c +++ b/drivers/net/ethernet/ti/netcp_core.c @@ -471,6 +471,7 @@ struct netcp_hook_list { int netcp_register_txhook(struct netcp_intf *netcp_priv, int order, netcp_hook_rtn *hook_rtn, void *hook_data) { + struct list_head *pos = &netcp_priv->txhook_list_head; struct netcp_hook_list *entry; struct netcp_hook_list *next; unsigned long flags; @@ -485,10 +486,12 @@ int netcp_register_txhook(struct netcp_intf *netcp_priv, int order, spin_lock_irqsave(&netcp_priv->lock, flags); list_for_each_entry(next, &netcp_priv->txhook_list_head, list) { - if (next->order > order) + if (next->order > order) { + pos = &next->list; break; + } } - __list_add(&entry->list, next->list.prev, &next->list); + list_add_tail(&entry->list, pos); spin_unlock_irqrestore(&netcp_priv->lock, flags); return 0; @@ -520,6 +523,7 @@ EXPORT_SYMBOL_GPL(netcp_unregister_txhook); int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order, netcp_hook_rtn *hook_rtn, void *hook_data) { + struct list_head *pos = &netcp_priv->rxhook_list_head; struct netcp_hook_list *entry; struct netcp_hook_list *next; unsigned long flags; @@ -534,10 +538,12 @@ int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order, spin_lock_irqsave(&netcp_priv->lock, flags); list_for_each_entry(next, &netcp_priv->rxhook_list_head, list) { - if (next->order > order) + if (next->order > order) { + pos = &next->list; break; + } } - __list_add(&entry->list, next->list.prev, &next->list); + list_add_tail(&entry->list, pos); spin_unlock_irqrestore(&netcp_priv->lock, flags); return 0; -- 2.25.1