Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp29178lfe; Fri, 15 Apr 2022 17:55:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEEklmhz7vo0KICnC/4Xz/8CAtbREVQCQOxQSu7o9BvEKMKm5p8b6LyyR0twcq2bt7icTR X-Received: by 2002:a63:5747:0:b0:381:54b9:b083 with SMTP id h7-20020a635747000000b0038154b9b083mr1202200pgm.178.1650070534802; Fri, 15 Apr 2022 17:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650070534; cv=none; d=google.com; s=arc-20160816; b=s9qRsa1LFiR0Pdk4dnDmH5cinAoY4QQ6ggLIhF88BwnUv6YJjPXNFyI09OJdyVL+qA WvUQzfFAjPD8MxWvGW9sOAwFOJ032AcePsKzR+HlKb15U1gSrBk3xynAVj6jezeiCtO6 YERUJRPRraYnQmMeY/+g+0cCp0CkbMpN/mBd/Jo4F0rOV1Q38PZMFVt+6UCcU2mZ1shQ RuwVPlAvxCKeM0WicXYVzzwC9Bzx3dhQfOJ0HzNeRXR3Up+bNaWH5Mp/0ZYpLwtehPg4 i/KEQxe1z72t9TdWXhdeoYNX6AWrOrxn090rMe/s1TsTRbRYsQ2iz9NPssCEA4KVB7N2 wGbg== 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=ISPVkMKXCg9cEI+UhNMRQDtHy3D7tL4p9utv3k88NAwHSkwdLiUhjMiCGpT+FLrTdP PryDHp6oV/sEYAapIJvRCApHlDAYKsBemNRQdeRwBsjIE4UP5U5SsBNdG8Ayc2actcWk p0ETL0jehHd3AjbHtrT7RXOhaeL8ipscjOpCMK0jhKjy67RdJaRDpdlmIUnsbPOiy5rX n4jusek5IxdR/WA7hHRqOQDJ1gdTntWSBZAPqvtf143JMyvUuZJlqdM0bP2+gX0BzYpF dVMRKPubbHN5e3a8Q88cNmcM2TIgqZwD/GnsXqze5GNy3pR1PrMk7Y6VHDQ82aom4vLF N7Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=J29YX3EE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id ns12-20020a17090b250c00b001cba0d1d3b4si2644914pjb.98.2022.04.15.17.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:55:34 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=J29YX3EE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 93E19111DF9; Fri, 15 Apr 2022 17:41:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353429AbiDOMfM (ORCPT + 99 others); Fri, 15 Apr 2022 08:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353387AbiDOMdg (ORCPT ); Fri, 15 Apr 2022 08:33:36 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D569329A7; Fri, 15 Apr 2022 05:31:08 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id bg10so15161617ejb.4; Fri, 15 Apr 2022 05:31:08 -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=J29YX3EEMEL7T374lnld4XKuYjiGeeoVO1klWLUIkfZJQeL2lLiOJu41mh8Mlrt/vB 0hc1mDL5NN2TTVjsBWWdsfB0RlH9u8WpBKvaSwodSk+R4GZNluAP3ZKaTkkPMlIbNlTk w9cBhCyuJv+3wLIzF/9Kc7oQdcKK/rIIWAVsgeZIVRYleGEFkaYTlnrjHromHPnbM1/7 3lP8wZeKMpEF3W4eWzvgySheAoJ/fSA4dloEVHWMNtpL4XJqAwi6ktnNLBkPCF3RqAtL FfsqZ0RtqT0it3Iyvym50ZYXeiMDeI0khBXLATZMg661vZKB6wij6XlgY68sJ/G4H+3v pltg== 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=QR1GbEDnXtxEMtwbQ1X4m8y7nR/oY8FcZKw6vY4U3nJYf3fKZ1e1bbg1ft8S1mH8ya AAe05Azb4UypRl3lh5rSBkgayy3THhNC7KExlXXciqZ5+PmIGyB5j8MtLFvFF5LADN9O DfDnNFNWmRivprUW3XjOsX52PKPeVpiGqCLdJYa0J7ZRF9Iw2ddygsS4I6wCw0veSX1Y IcZJQjZFQuaNHyOsx4O23iFK7/xlxnmbjyb6EfejCkFYf7dOs8xAQlN2rpODcCL6zFvk ZD3ySdt1r3DEY5HsmIG9QLFft5hZuoj1VGYQfm5UlQrGMH+YVglxtkYutsiwA4p8gNvF UIRA== X-Gm-Message-State: AOAM533YIBcmsj5kEXuBL3hGM88QGnIwNVHtoAL7sYDQBkMDqiFo41RE mEqmWcV7KG/tDV+dWqKIW0w= X-Received: by 2002:a17:907:6d9b:b0:6db:8eab:94e0 with SMTP id sb27-20020a1709076d9b00b006db8eab94e0mr5947836ejc.687.1650025866683; Fri, 15 Apr 2022 05:31:06 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id bo14-20020a170906d04e00b006ce98d9c3e3sm1649533ejb.194.2022.04.15.05.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 05:31:06 -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 , Bjarni Jonasson , Jakob Koschel , Christophe JAILLET , Arnd Bergmann , Colin Ian King , 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 v4 15/18] net: netcp: Remove usage of list iterator for list_add() after loop body Date: Fri, 15 Apr 2022 14:29:44 +0200 Message-Id: <20220415122947.2754662-16-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220415122947.2754662-1-jakobkoschel@gmail.com> References: <20220415122947.2754662-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