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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9163EC433FE for ; Thu, 7 Apr 2022 10:32:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243687AbiDGKek (ORCPT ); Thu, 7 Apr 2022 06:34:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244328AbiDGKdi (ORCPT ); Thu, 7 Apr 2022 06:33:38 -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 A736CC1CBA; Thu, 7 Apr 2022 03:31:17 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id bq8so9852331ejb.10; Thu, 07 Apr 2022 03:31:17 -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=MSY1nTudb+PZHTwNW0++Hw3ZkegN7YQIOboMBZ6jBg0=; b=Brx4PkxB2qdWTRw7gD0HT3PEDbMMWi0XZkbblBnTtAVRKFZm8RAn4P1cLxUzGaUSWj r6JxWEq0muCi0zq0RyRsEDl8YQa7DCNKZBC1Gj5rF17+x2LK3VvqVWEVI6k/8DvOCHIq xClZCgthVxp4u5kv6LFjYJJnSkK1bZEibqrgmMQ0JP8dYZ+15cOAVnkRAzi3IgoT+dqm k4uFx+UARieV2bsoVD67F5Xff9RQaJx4M76B8zZgTKoP9mHwlZS7m8uDs2+oJzpKPok8 ktve3WHvQOVXDYKLjmG23a4XmTmuEu3OvZtYcVC0FpEHV2nWXBTKR8Gatcf/PU9USmof mfYg== 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=MSY1nTudb+PZHTwNW0++Hw3ZkegN7YQIOboMBZ6jBg0=; b=ckTcCs6ZE6xhKT2L22ndE8SCvAvO9GcuOf8zM6maRdqkuucT7RsL2akx70vST9v0nF YCBjioYlahIsz59Hq4C5oPPnJMjqfd8Ykm4pp7/wM2QF5EO5qnwq2EBSCkx6Hy8trrb7 MOstPNETajqcAnvDvBS1nrapMwwvzNpBtZBvXpSYHVLGDFtLg3P8zWONXB9kb2jje9Jd me2xHG6QcmEF1DOheH8Xjv98yJEgvM3yBzBLt7jIFzGLZq/pwGK2iAnknYeCh+6DSxGC Hh1eUtLwZh/jxlLEOkuP08WRWIvvq4W/HBpDTEy9jYH6SGhmAzgwYf0r/4xqJC1H8Gb4 novQ== X-Gm-Message-State: AOAM532ZB7otaXQTIW/yAvBksqnn+Fcoy/fruAVOGE9t8bG16uejSUxt 6zxCxurfG+TLlcLehtcZPvM= X-Google-Smtp-Source: ABdhPJwwT5jmVo5qc9B+eZATYpRQi7yTuAnE1UXZHjgZUgliXLWJp7twbPBsvZlMRQCsjFWFpTIFiQ== X-Received: by 2002:a17:907:7f1a:b0:6e8:4127:6bc4 with SMTP id qf26-20020a1709077f1a00b006e841276bc4mr375201ejc.496.1649327476146; Thu, 07 Apr 2022 03:31:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 03:31:15 -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 12/15] net: netcp: Remove usage of list iterator for list_add() after loop body Date: Thu, 7 Apr 2022 12:28:57 +0200 Message-Id: <20220407102900.3086255-13-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 Content-Transfer-Encoding: 8bit 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 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/ethernet/ti/netcp_core.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c index 16507bff652a..7f89fd82ecc8 100644 --- a/drivers/net/ethernet/ti/netcp_core.c +++ b/drivers/net/ethernet/ti/netcp_core.c @@ -471,8 +471,8 @@ struct netcp_hook_list { int netcp_register_txhook(struct netcp_intf *netcp_priv, int order, netcp_hook_rtn *hook_rtn, void *hook_data) { + struct netcp_hook_list *next = NULL, *iter; struct netcp_hook_list *entry; - struct netcp_hook_list *next; unsigned long flags; entry = devm_kzalloc(netcp_priv->dev, sizeof(*entry), GFP_KERNEL); @@ -484,11 +484,15 @@ int netcp_register_txhook(struct netcp_intf *netcp_priv, int order, entry->order = order; spin_lock_irqsave(&netcp_priv->lock, flags); - list_for_each_entry(next, &netcp_priv->txhook_list_head, list) { - if (next->order > order) + list_for_each_entry(iter, &netcp_priv->txhook_list_head, list) { + if (iter->order > order) { + next = iter; + list_add_tail(&entry->list, &iter->list); break; + } } - __list_add(&entry->list, next->list.prev, &next->list); + if (!next) + list_add_tail(&entry->list, &netcp_priv->txhook_list_head); spin_unlock_irqrestore(&netcp_priv->lock, flags); return 0; @@ -520,8 +524,8 @@ 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 netcp_hook_list *next = NULL, *iter; struct netcp_hook_list *entry; - struct netcp_hook_list *next; unsigned long flags; entry = devm_kzalloc(netcp_priv->dev, sizeof(*entry), GFP_KERNEL); @@ -533,11 +537,15 @@ int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order, entry->order = order; spin_lock_irqsave(&netcp_priv->lock, flags); - list_for_each_entry(next, &netcp_priv->rxhook_list_head, list) { - if (next->order > order) + list_for_each_entry(iter, &netcp_priv->rxhook_list_head, list) { + if (iter->order > order) { + next = iter; + list_add_tail(&entry->list, &iter->list); break; + } } - __list_add(&entry->list, next->list.prev, &next->list); + if (!next) + list_add_tail(&entry->list, &netcp_priv->rxhook_list_head); spin_unlock_irqrestore(&netcp_priv->lock, flags); return 0; -- 2.25.1 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 21F6DC433F5 for ; Thu, 7 Apr 2022 10:39:01 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KYyXz5p3Mz3c9T for ; Thu, 7 Apr 2022 20:38:59 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Brx4PkxB; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::635; helo=mail-ej1-x635.google.com; envelope-from=jakobkoschel@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Brx4PkxB; dkim-atps=neutral Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KYyN70M8mz3bXG for ; Thu, 7 Apr 2022 20:31:19 +1000 (AEST) Received: by mail-ej1-x635.google.com with SMTP id dr20so9836627ejc.6 for ; Thu, 07 Apr 2022 03:31:18 -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=MSY1nTudb+PZHTwNW0++Hw3ZkegN7YQIOboMBZ6jBg0=; b=Brx4PkxB2qdWTRw7gD0HT3PEDbMMWi0XZkbblBnTtAVRKFZm8RAn4P1cLxUzGaUSWj r6JxWEq0muCi0zq0RyRsEDl8YQa7DCNKZBC1Gj5rF17+x2LK3VvqVWEVI6k/8DvOCHIq xClZCgthVxp4u5kv6LFjYJJnSkK1bZEibqrgmMQ0JP8dYZ+15cOAVnkRAzi3IgoT+dqm k4uFx+UARieV2bsoVD67F5Xff9RQaJx4M76B8zZgTKoP9mHwlZS7m8uDs2+oJzpKPok8 ktve3WHvQOVXDYKLjmG23a4XmTmuEu3OvZtYcVC0FpEHV2nWXBTKR8Gatcf/PU9USmof mfYg== 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=MSY1nTudb+PZHTwNW0++Hw3ZkegN7YQIOboMBZ6jBg0=; b=HqytMwSWf6rNzlNY5AWzA+AG4KaJxqIJm710PTGingck8LctX7LN25VSfm9eJoVvyc n9+A/xUYufAKpVOmLniyB7BWKIB8LZ/qZQ5JvA/Z0zfldXXRbA0UccCZKbjNy4lOl5fC Q66XoPjk0CoT1PdUJH+bVysNn6GYx4lNFI9/02ZtXhCe9R2cRzmpBb+EWbBu+2a4MiEb +BlSt90d9jV3dbb72YudGlb78eZslYpljIr/KA4sOnNTTDiT0n4iLWw2Qedzdkq6W9ug 797rBco14nkpobR+q4xuVFQlGbnYSUU7U+7v8WMMc9Jh4pdjhMjjV82x7OAcIrt6GRvE PGqw== X-Gm-Message-State: AOAM530p+XcjbwN9q37+xszT5o4wJQ1IMTvaGaVlb2F03Tc6ArvFhvat TqOBQ7HUzE2PKFOTzpxEXIA= X-Google-Smtp-Source: ABdhPJwwT5jmVo5qc9B+eZATYpRQi7yTuAnE1UXZHjgZUgliXLWJp7twbPBsvZlMRQCsjFWFpTIFiQ== X-Received: by 2002:a17:907:7f1a:b0:6e8:4127:6bc4 with SMTP id qf26-20020a1709077f1a00b006e841276bc4mr375201ejc.496.1649327476146; Thu, 07 Apr 2022 03:31:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 03:31:15 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next 12/15] net: netcp: Remove usage of list iterator for list_add() after loop body Date: Thu, 7 Apr 2022 12:28:57 +0200 Message-Id: <20220407102900.3086255-13-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 Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Lunn , Cristiano Giuffrida , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Manish Chopra , Steen Hegelund , "Bos, H.J." , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Bjarni Jonasson , Jiri Pirko , Arnd Bergmann , Brian Johannesmeyer , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Di Zhu , Lars Povlsen , Colin Ian King , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Edward Cree , Michael Walle , Xu Wang , Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Casper Andersson , Mike Rapoport Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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/ethernet/ti/netcp_core.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c index 16507bff652a..7f89fd82ecc8 100644 --- a/drivers/net/ethernet/ti/netcp_core.c +++ b/drivers/net/ethernet/ti/netcp_core.c @@ -471,8 +471,8 @@ struct netcp_hook_list { int netcp_register_txhook(struct netcp_intf *netcp_priv, int order, netcp_hook_rtn *hook_rtn, void *hook_data) { + struct netcp_hook_list *next = NULL, *iter; struct netcp_hook_list *entry; - struct netcp_hook_list *next; unsigned long flags; entry = devm_kzalloc(netcp_priv->dev, sizeof(*entry), GFP_KERNEL); @@ -484,11 +484,15 @@ int netcp_register_txhook(struct netcp_intf *netcp_priv, int order, entry->order = order; spin_lock_irqsave(&netcp_priv->lock, flags); - list_for_each_entry(next, &netcp_priv->txhook_list_head, list) { - if (next->order > order) + list_for_each_entry(iter, &netcp_priv->txhook_list_head, list) { + if (iter->order > order) { + next = iter; + list_add_tail(&entry->list, &iter->list); break; + } } - __list_add(&entry->list, next->list.prev, &next->list); + if (!next) + list_add_tail(&entry->list, &netcp_priv->txhook_list_head); spin_unlock_irqrestore(&netcp_priv->lock, flags); return 0; @@ -520,8 +524,8 @@ 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 netcp_hook_list *next = NULL, *iter; struct netcp_hook_list *entry; - struct netcp_hook_list *next; unsigned long flags; entry = devm_kzalloc(netcp_priv->dev, sizeof(*entry), GFP_KERNEL); @@ -533,11 +537,15 @@ int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order, entry->order = order; spin_lock_irqsave(&netcp_priv->lock, flags); - list_for_each_entry(next, &netcp_priv->rxhook_list_head, list) { - if (next->order > order) + list_for_each_entry(iter, &netcp_priv->rxhook_list_head, list) { + if (iter->order > order) { + next = iter; + list_add_tail(&entry->list, &iter->list); break; + } } - __list_add(&entry->list, next->list.prev, &next->list); + if (!next) + list_add_tail(&entry->list, &netcp_priv->rxhook_list_head); spin_unlock_irqrestore(&netcp_priv->lock, flags); return 0; -- 2.25.1 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 8A8DCC433F5 for ; Thu, 7 Apr 2022 10:38:28 +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=BP8iTMciqsAa2HiCWkpLxVjr93N0j2CoH3Jnc9fg4Nk=; b=BRSGdjX1uvuEAN bGnwJSanQfuDKq8tNNDu7IfHMkcMdHAmeCemC8njI7Yv9sQTTOULQbJIgWx0ZKb+DCruGDmiMCYYN b3bOYfMjiJtwcWiotsCxix35V7Qpxmj+cSmlJXAMRsGKm21lNYK9x5wibs0Cz1aPfMqRdRFmlpU+p S23CclAXtCce5pQJ65uazG6hpSonUKAG22/VFVn8sx56vYwgrRf3xVHXBIwwgXdDBvg8scJXIf4w3 /kV/CCtYavWpeq6b0fWKEuQQ567qX/gZFO3zQSrQX5yjVDkVYs4DAVaB3Vrg2wrMuEddC8+xcg6l5 n4K3WUvSoijARgnbqpzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncPVe-00BHIk-Fw; Thu, 07 Apr 2022 10:37:03 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncPQ8-00BEHb-0X for linux-arm-kernel@lists.infradead.org; Thu, 07 Apr 2022 10:31:21 +0000 Received: by mail-ej1-x62d.google.com with SMTP id i27so9864352ejd.9 for ; Thu, 07 Apr 2022 03:31:17 -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=MSY1nTudb+PZHTwNW0++Hw3ZkegN7YQIOboMBZ6jBg0=; b=Brx4PkxB2qdWTRw7gD0HT3PEDbMMWi0XZkbblBnTtAVRKFZm8RAn4P1cLxUzGaUSWj r6JxWEq0muCi0zq0RyRsEDl8YQa7DCNKZBC1Gj5rF17+x2LK3VvqVWEVI6k/8DvOCHIq xClZCgthVxp4u5kv6LFjYJJnSkK1bZEibqrgmMQ0JP8dYZ+15cOAVnkRAzi3IgoT+dqm k4uFx+UARieV2bsoVD67F5Xff9RQaJx4M76B8zZgTKoP9mHwlZS7m8uDs2+oJzpKPok8 ktve3WHvQOVXDYKLjmG23a4XmTmuEu3OvZtYcVC0FpEHV2nWXBTKR8Gatcf/PU9USmof mfYg== 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=MSY1nTudb+PZHTwNW0++Hw3ZkegN7YQIOboMBZ6jBg0=; b=6io4IK3EtnxxX0HnfKCwGDWWkUF7xolCfOBp8PrXcPCnodoRm3WHc7T2e29UMvjQGy eiqz0WgGktuJ+HUxnzyAC1a8bLflQAGVpy4HkM72shUEysRIiDPtU44dIzYKeQVn4Lj5 gzdzTd5MEAGigOhehiRgllME9sAIFXxre6SoMUXdd3YKmgQ63X1CJLox5eplTjEC5mhM +tFYzZ9dWrLunYBB4cS0aHlkMohp6mkLG/Id52bIr2fEsu9BgbVmJCUnarqeTgf6Jz0O mPy90rktV9iHx4JBkTNxngcog1hc49lTXqv9upatHK44GYXgF5G2p7H88xD6RDL9fRwH 3I4Q== X-Gm-Message-State: AOAM530EVbVM8B5I+OK2sdHwfJFF3l9w/ROJ9ZXVq95VMj6UdiX9+cB/ 0fOP2zRoGvQOAdSlHw3Qhlw= X-Google-Smtp-Source: ABdhPJwwT5jmVo5qc9B+eZATYpRQi7yTuAnE1UXZHjgZUgliXLWJp7twbPBsvZlMRQCsjFWFpTIFiQ== X-Received: by 2002:a17:907:7f1a:b0:6e8:4127:6bc4 with SMTP id qf26-20020a1709077f1a00b006e841276bc4mr375201ejc.496.1649327476146; Thu, 07 Apr 2022 03:31:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 03:31:15 -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 12/15] net: netcp: Remove usage of list iterator for list_add() after loop body Date: Thu, 7 Apr 2022 12:28:57 +0200 Message-Id: <20220407102900.3086255-13-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_033120_119017_8EDB1959 X-CRM114-Status: GOOD ( 16.94 ) 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/ethernet/ti/netcp_core.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c index 16507bff652a..7f89fd82ecc8 100644 --- a/drivers/net/ethernet/ti/netcp_core.c +++ b/drivers/net/ethernet/ti/netcp_core.c @@ -471,8 +471,8 @@ struct netcp_hook_list { int netcp_register_txhook(struct netcp_intf *netcp_priv, int order, netcp_hook_rtn *hook_rtn, void *hook_data) { + struct netcp_hook_list *next = NULL, *iter; struct netcp_hook_list *entry; - struct netcp_hook_list *next; unsigned long flags; entry = devm_kzalloc(netcp_priv->dev, sizeof(*entry), GFP_KERNEL); @@ -484,11 +484,15 @@ int netcp_register_txhook(struct netcp_intf *netcp_priv, int order, entry->order = order; spin_lock_irqsave(&netcp_priv->lock, flags); - list_for_each_entry(next, &netcp_priv->txhook_list_head, list) { - if (next->order > order) + list_for_each_entry(iter, &netcp_priv->txhook_list_head, list) { + if (iter->order > order) { + next = iter; + list_add_tail(&entry->list, &iter->list); break; + } } - __list_add(&entry->list, next->list.prev, &next->list); + if (!next) + list_add_tail(&entry->list, &netcp_priv->txhook_list_head); spin_unlock_irqrestore(&netcp_priv->lock, flags); return 0; @@ -520,8 +524,8 @@ 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 netcp_hook_list *next = NULL, *iter; struct netcp_hook_list *entry; - struct netcp_hook_list *next; unsigned long flags; entry = devm_kzalloc(netcp_priv->dev, sizeof(*entry), GFP_KERNEL); @@ -533,11 +537,15 @@ int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order, entry->order = order; spin_lock_irqsave(&netcp_priv->lock, flags); - list_for_each_entry(next, &netcp_priv->rxhook_list_head, list) { - if (next->order > order) + list_for_each_entry(iter, &netcp_priv->rxhook_list_head, list) { + if (iter->order > order) { + next = iter; + list_add_tail(&entry->list, &iter->list); break; + } } - __list_add(&entry->list, next->list.prev, &next->list); + if (!next) + list_add_tail(&entry->list, &netcp_priv->rxhook_list_head); spin_unlock_irqrestore(&netcp_priv->lock, flags); return 0; -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel