From patchwork Wed Apr 27 16:06:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623110 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=A8Htft4E; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpNvP0Bq4z9s5V for ; Thu, 28 Apr 2022 02:08:01 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpNvN3t0Vz3bhB for ; Thu, 28 Apr 2022 02:08:00 +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=A8Htft4E; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::631; helo=mail-ej1-x631.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=A8Htft4E; dkim-atps=neutral Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) (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 4KpNtb6Gxfz3bY6 for ; Thu, 28 Apr 2022 02:07:18 +1000 (AEST) Received: by mail-ej1-x631.google.com with SMTP id l7so4395655ejn.2 for ; Wed, 27 Apr 2022 09:07: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=cM7cNDbZdzDRR54XOLUdiPP1jrQ7jBG9dEAYVsbcNLE=; b=A8Htft4EvwT9SqEU+mp432FPrRkA/A2mubCUNTACbh+9ZsCDSEQeCbubYFCiwV7et2 32mxvLXoLsmy0FtItW3NCx3Y+UPEdZSLQ34uE6is2mvJFMXm5umdPUJMLfzfJhTfmTi9 v1Po3076bdspN+L8sUvAzgbuQCbpJrqPGIUfhUwNKeBCU4j2xZ7cO+oHyyX9Bm/D3avW jH2X/eRwkEoQkduB1jvkosr6wCQJvcQSFprdpnTZhOOATniOAsisRbmktjQ8at7BSBVA p1AtT1AEESuli07A4n8ALTyJJVp7iEYcOTqOBMEs3Aospfy47uA1kxAMV7zbRYd6g9ao /KMg== 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=cM7cNDbZdzDRR54XOLUdiPP1jrQ7jBG9dEAYVsbcNLE=; b=FRsbx4lZyWlwbHudYKSys+OpQmBF1Awcp+5nFeQhJLKjPD+/XwOluHEHbt/iaxaR95 fm3wP3gvNZh5/xTRKvpgfDC4i7xyobCRGJ/C5OqFZPkL0Lkzi7h9W7aWWYqREVGTEeLf TvG/pnc8hxaesDf2idAgKyNBVn2Mo5CqIcyalvLG9k18axPN6mjMvGXks4u2UnJSv/gT ZHV7bbMIlbNu43zlY41EO3T0K97/Zgl+rm0+9JWICMyXUHWZazIMs4tBMRfG4c1+03Sj sUnPurlDAgMu1vWK7J938uc/HeX+ScN6ax7Z4mLHijFt5Sn92J53LI/KBPhLwEbl+aZu IPgQ== X-Gm-Message-State: AOAM533jR73P0+4OEaAPjRxriH78+V3zi84073ZJk0eOxH1rCUyIV+9u 6xyhV4gOPR3PHgxcvJ7UPNE= X-Google-Smtp-Source: ABdhPJy+HnRcSWnVRLCgUM5UWKbVkDZcybwwpqzCGQ74DeVD0/Q0cuvO1YJJg3e+zws6FzlT91P3jw== X-Received: by 2002:a17:906:824a:b0:6f3:a07b:2568 with SMTP id f10-20020a170906824a00b006f3a07b2568mr12694721ejx.84.1651075635044; Wed, 27 Apr 2022 09:07:15 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:14 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 01/18] connector: Replace usage of found with dedicated list iterator variable Date: Wed, 27 Apr 2022 18:06:18 +0200 Message-Id: <20220427160635.420492-2-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 instead of a found boolean [1]. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- drivers/connector/cn_queue.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/connector/cn_queue.c b/drivers/connector/cn_queue.c index 996f025eb63c..ed77599b0b25 100644 --- a/drivers/connector/cn_queue.c +++ b/drivers/connector/cn_queue.c @@ -92,20 +92,19 @@ int cn_queue_add_callback(struct cn_queue_dev *dev, const char *name, void cn_queue_del_callback(struct cn_queue_dev *dev, const struct cb_id *id) { - struct cn_callback_entry *cbq, *n; - int found = 0; + struct cn_callback_entry *cbq = NULL, *iter, *n; spin_lock_bh(&dev->queue_lock); - list_for_each_entry_safe(cbq, n, &dev->queue_list, callback_entry) { - if (cn_cb_equal(&cbq->id.id, id)) { - list_del(&cbq->callback_entry); - found = 1; + list_for_each_entry_safe(iter, n, &dev->queue_list, callback_entry) { + if (cn_cb_equal(&iter->id.id, id)) { + list_del(&iter->callback_entry); + cbq = iter; break; } } spin_unlock_bh(&dev->queue_lock); - if (found) + if (cbq) cn_queue_release_callback(cbq); } From patchwork Wed Apr 27 16:06:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=gTz2VhWR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpNw42PZRz9s5V for ; Thu, 28 Apr 2022 02:08:36 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpNw407jPz3br2 for ; Thu, 28 Apr 2022 02:08:36 +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=gTz2VhWR; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::536; helo=mail-ed1-x536.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=gTz2VhWR; dkim-atps=neutral Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) (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 4KpNtc10Nkz3bYy for ; Thu, 28 Apr 2022 02:07:19 +1000 (AEST) Received: by mail-ed1-x536.google.com with SMTP id d6so2497920ede.8 for ; Wed, 27 Apr 2022 09:07:19 -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=Ry4cO5XKq+tSuqaPwnaD/oB6fR112JLGwCzZrnPEBlA=; b=gTz2VhWRMedOoCha0T1KppSjULk3Bc0IGbzfh8dYjxj0EMR9lXQhicmKaHe9WX8kjX EDzy4DCZgowX8w66jFwEOxdW3OJWSpKXEb7hLc2rGLcGjJLW94luIc1K0woOWuGAT6bs eoru8bk/NksbqyIbrM7zkCX7jp4W8Z+Cl9BI99WOHmGOROz4wHLvdYp6mjCsCPb+XEn2 Aj5pJkeUi6siV5Ti4LW9sACgwKybqhKcVft6ZEOaacEDZVOn6HcPQyUSbRyYwyWCSu16 20AZk0c6WgnbUFseXQhY7NzwsMpDGqhwzgBrDYQdHOZ/vTTYz6MtyG/AlxQQ/ooEqthL PwCA== 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=Ry4cO5XKq+tSuqaPwnaD/oB6fR112JLGwCzZrnPEBlA=; b=QaHAvnENtAzvgRd+y7PhXU/3eJmYJIF5VHKJn9+a8oImilgS5JCQhB9ENMe2LawgPV nftyqpbQA3HP3QpQtDFWusIfVf95jvWiYd0gu9U5VW+enhOf6BQOuvxJSZLBeZn7TcGy DKq+KnnW0Jn/OpLDIseSKvIuraCx52ekKCjHSX7hgRMAW2NRpWIBNtWiebc//NIg/vLJ nsw6s6YX7J8eYEIjQqc8JD49crAJS3r0bIyNPBYxDHlCFVZNU9fiPPBksBHcmxAPEyad r9nyXDXU1d0ADdPgN+Ep7hSt+uAC/UKqbtKkcp0iweI/JFKIATgu0uOlMWDjYIH2nqfO pEbA== X-Gm-Message-State: AOAM530cnnuY/pcq1yytOIV8M3+1tv2Uf3lRtUC4S+zJLRX009Lm36ec zkAp38quc8JXo8tYUabxW+I= X-Google-Smtp-Source: ABdhPJzmxCEbRgdEJxeGjIzOLAzD6Jz8BmWV4O0tXcBy7605EBHJeCvxAjeCBnzVK+USBG4J1UHv1Q== X-Received: by 2002:a05:6402:486:b0:413:bd00:4f3f with SMTP id k6-20020a056402048600b00413bd004f3fmr31661472edv.103.1651075636619; Wed, 27 Apr 2022 09:07:16 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:16 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 02/18] net: dsa: sja1105: remove use of iterator after list_for_each_entry() loop Date: Wed, 27 Apr 2022 18:06:19 +0200 Message-Id: <20220427160635.420492-3-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Vladimir Oltean , Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Vladimir Oltean The link below explains that there is a desire to syntactically change list_for_each_entry() and list_for_each() such that it becomes impossible to use the iterator variable outside the scope of the loop. Although sja1105_insert_gate_entry() makes legitimate use of the iterator pointer when it breaks out, the pattern it uses may become illegal, so it needs to change. It is deemed acceptable to use a copy of the loop iterator, and sja1105_insert_gate_entry() only needs to know the list_head element before which the list insertion should be made. So let's profit from the occasion and refactor the list iteration to a dedicated function. An additional benefit is given by the fact that with the helper function in place, we no longer need to special-case the empty list, since it is equivalent to not having found any gating entry larger than the specified interval in the list. We just need to insert at the tail of that list (list_add vs list_add_tail on an empty list does the same thing). Link: https://patchwork.kernel.org/project/netdevbpf/patch/20220407102900.3086255-3-jakobkoschel@gmail.com/#24810127 Signed-off-by: Vladimir Oltean Signed-off-by: Jakob Koschel Reviewed-by: Florian Fainelli --- drivers/net/dsa/sja1105/sja1105_vl.c | 46 ++++++++++++++++++---------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_vl.c b/drivers/net/dsa/sja1105/sja1105_vl.c index b7e95d60a6e4..369be2ac3587 100644 --- a/drivers/net/dsa/sja1105/sja1105_vl.c +++ b/drivers/net/dsa/sja1105/sja1105_vl.c @@ -7,6 +7,27 @@ #define SJA1105_SIZE_VL_STATUS 8 +static struct list_head * +sja1105_first_entry_longer_than(struct list_head *entries, + s64 interval, + struct netlink_ext_ack *extack) +{ + struct sja1105_gate_entry *p; + + list_for_each_entry(p, entries, list) { + if (p->interval == interval) { + NL_SET_ERR_MSG_MOD(extack, "Gate conflict"); + return ERR_PTR(-EBUSY); + } + + if (interval < p->interval) + return &p->list; + } + + /* Empty list, or specified interval is largest within the list */ + return entries; +} + /* Insert into the global gate list, sorted by gate action time. */ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, struct sja1105_rule *rule, @@ -14,6 +35,7 @@ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, struct netlink_ext_ack *extack) { struct sja1105_gate_entry *e; + struct list_head *pos; int rc; e = kzalloc(sizeof(*e), GFP_KERNEL); @@ -24,25 +46,15 @@ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, e->gate_state = gate_state; e->interval = entry_time; - if (list_empty(&gating_cfg->entries)) { - list_add(&e->list, &gating_cfg->entries); - } else { - struct sja1105_gate_entry *p; - - list_for_each_entry(p, &gating_cfg->entries, list) { - if (p->interval == e->interval) { - NL_SET_ERR_MSG_MOD(extack, - "Gate conflict"); - rc = -EBUSY; - goto err; - } - - if (e->interval < p->interval) - break; - } - list_add(&e->list, p->list.prev); + pos = sja1105_first_entry_longer_than(&gating_cfg->entries, + e->interval, extack); + if (IS_ERR(pos)) { + rc = PTR_ERR(pos); + goto err; } + list_add(&e->list, pos->prev); + gating_cfg->num_entries++; return 0; From patchwork Wed Apr 27 16:06:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623112 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=UamABqmz; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpNwm5LdMz9s5V for ; Thu, 28 Apr 2022 02:09:12 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpNwm46zYz3bgV for ; Thu, 28 Apr 2022 02:09:12 +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=UamABqmz; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::52c; helo=mail-ed1-x52c.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=UamABqmz; dkim-atps=neutral Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) (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 4KpNtd3ZKLz3bYM for ; Thu, 28 Apr 2022 02:07:21 +1000 (AEST) Received: by mail-ed1-x52c.google.com with SMTP id g23so2477764edy.13 for ; Wed, 27 Apr 2022 09:07:21 -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=fEe777jf21mNuBLYmQSjDhGs0vKSqwrqRu+k2WAlJJI=; b=UamABqmz85uwD6pNa9ppky+li2Rl66SIvHGPZAkZVVplDfguBN2gvzOkJOhaiRqNGo w4fvmZjgVfGNJF5AOxd1tcte4r2cbB7t/uoyu4KztE/vthdmIXv5I6UY49yp1+DYS7Xh 9j/TlXjAQ2gDG8dwmHMyRfHk1Kw64P83QqoqtW05BXmUo7o/LsgKDe8SC8J+Sghxk4zd 335vq71ir8P7aETUROxG1BwEZox7dWCMHuxGLLBDs7zGmUOfhUYMOY+X+cEaRcJgk1PB GzHiotygYFSraZoVwVsqkjC3NHG10ku3IkPGBiw38mQdLc4oh1SaC8DmzpJzLf5WJ73Y AhTw== 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=fEe777jf21mNuBLYmQSjDhGs0vKSqwrqRu+k2WAlJJI=; b=urc/t+o/WK2HPHL1lolnESUq96NTa0m2921hxc/08etZFMLOtpH6yTWOlRAhBLFnUf cM9FUTvceGJH1Ebt6/svlq7P4olRAxx8HL6PhNlVCbft6mKjxdQxxGwknvVSlm3+7+px rtXVgDxy6Lps8po1uubB0diYWq01FEWzwTgZWuy1lwFVtBooN3MXMU0yJGy4D14Un+NN aWh1q30TKiuRz+Bq0I4k5ETr7PDOVnL4cBjYxe/+HkrFaruB03qQUwIIUmFQiIY9g9LV c+o+THEvokhcUegsUNe3tia4MABjRvdl1AP9V4NquxqVOT/manWX6fCImQyM+Kq1aEmL CSXQ== X-Gm-Message-State: AOAM532ZXQszNKz49hdfgeSzJ1gmqkdwSowEgFw+4VVnq+ojX6MR2cIY UevAAaWqAoa27Oq+I/uAgnA= X-Google-Smtp-Source: ABdhPJySlXKZf47ps6kDqshs4fRxCzYc+L5zpCq3TvKUZGNFin1KNz+UcjSbrxBlctSBknb4gNbpAw== X-Received: by 2002:aa7:dd45:0:b0:425:8cea:8c76 with SMTP id o5-20020aa7dd45000000b004258cea8c76mr30819280edw.353.1651075637990; Wed, 27 Apr 2022 09:07:17 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:17 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 03/18] net: dsa: sja1105: reorder sja1105_first_entry_longer_than with memory allocation Date: Wed, 27 Apr 2022 18:06:20 +0200 Message-Id: <20220427160635.420492-4-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Vladimir Oltean , Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Vladimir Oltean sja1105_first_entry_longer_than() does not make use of the full struct sja1105_gate_entry *e, just of e->interval which is set from the passed entry_time. This means that if there is a gate conflict, we have allocated e for nothing, just to free it later. Reorder the memory allocation and the function call, to avoid that and simplify the error unwind path. Signed-off-by: Vladimir Oltean Signed-off-by: Jakob Koschel Reviewed-by: Florian Fainelli --- drivers/net/dsa/sja1105/sja1105_vl.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_vl.c b/drivers/net/dsa/sja1105/sja1105_vl.c index 369be2ac3587..e5ea8eb9ec4e 100644 --- a/drivers/net/dsa/sja1105/sja1105_vl.c +++ b/drivers/net/dsa/sja1105/sja1105_vl.c @@ -36,7 +36,11 @@ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, { struct sja1105_gate_entry *e; struct list_head *pos; - int rc; + + pos = sja1105_first_entry_longer_than(&gating_cfg->entries, + entry_time, extack); + if (IS_ERR(pos)) + return PTR_ERR(pos); e = kzalloc(sizeof(*e), GFP_KERNEL); if (!e) @@ -45,22 +49,11 @@ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, e->rule = rule; e->gate_state = gate_state; e->interval = entry_time; - - pos = sja1105_first_entry_longer_than(&gating_cfg->entries, - e->interval, extack); - if (IS_ERR(pos)) { - rc = PTR_ERR(pos); - goto err; - } - list_add(&e->list, pos->prev); gating_cfg->num_entries++; return 0; -err: - kfree(e); - return rc; } /* The gate entries contain absolute times in their e->interval field. Convert From patchwork Wed Apr 27 16:06:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=me/CfCMU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpNxS5ysQz9s5V for ; Thu, 28 Apr 2022 02:09:48 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpNxS4RFMz3c8t for ; Thu, 28 Apr 2022 02:09:48 +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=me/CfCMU; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org 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=me/CfCMU; 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 4KpNtf6DQ6z3bYM for ; Thu, 28 Apr 2022 02:07:22 +1000 (AEST) Received: by mail-ej1-x635.google.com with SMTP id g6so4400938ejw.1 for ; Wed, 27 Apr 2022 09:07:22 -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=L7bydI8W7YKPMa0QpXcwp0iK03JxiA65XfYkLVk338s=; b=me/CfCMUzGN50v7aHW31BqgSnLtBSZmfvAHp5J7/hmxJn1cJoAxJnDiUBPmp28ldHA +GqEMGf2wiZIuh3K2rqkDck0yOW+vzBJCFtMKxdknc1uVNxKJEZ4gxdJDskKAyWsUucb 6bMeInlzy6Of9d/Pc22rBibJlCHrw/7AAwcu0id7P82U2wisfojvpL4x2jLueBTGDEWj aa6wF7qFHEu5HxnjRJS6k8c6Bb86bjEUZA/Me25yzxMt+DdMujV13iTbg8BjgNoSGdRS x2cDpFPCekknCFLP4V5Ou6fIx7tnmJ9Us5hq32MYbmFhIFLrYWL0JQyecgu0p5TtMAPg CnBw== 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=L7bydI8W7YKPMa0QpXcwp0iK03JxiA65XfYkLVk338s=; b=N/s3p/Go1YpB4j/dUoroteplXHfGEs8cpWlVsbQmQGXSCdIML2s49+QJO7Nkrkaa6f ewW/VRTVtrkIir+dB6W2g0G3E9/tsbJBm/LJSRXEEH0bkE02wnA/q8sy6aJlOLB820dE rsqbJA9WjrGoJYYctY77XuyUrFkklXUI+/nOzP09PIDDQjimSt7NcP7+lzS0SyBzmDZN 29GrVrXt33Ek5KSfFE0FVbAaY3QQAZc7pAg/CQx7P2MiuW6o3lInqGoxJ0+PXLjFu2v3 ylqWUf0dR4SYJ7sODnbQXzpP7HZvUiso2jKNrsl0tf+EekouS6obvfSNvbEsOPC00jMG bASQ== X-Gm-Message-State: AOAM5333zZgPTCL0GDCXkAVhXm+whCz25IFPuXROCbNTCR6hGkWit4qT cGTkrgJXrj5H551Cgt7RNR4= X-Google-Smtp-Source: ABdhPJwwQoZUzxJmxpPntFxcSAdUjkXDepMPzp8vysDK8FHgvVFqmw1HOME8T7SbR/DvsIrbGQJogQ== X-Received: by 2002:a17:906:5d11:b0:6f3:722a:1fee with SMTP id g17-20020a1709065d1100b006f3722a1feemr21285729ejt.9.1651075639369; Wed, 27 Apr 2022 09:07:19 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:19 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 04/18] net: dsa: sja1105: use list_add_tail(pos) instead of list_add(pos->prev) Date: Wed, 27 Apr 2022 18:06:21 +0200 Message-Id: <20220427160635.420492-5-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Vladimir Oltean , Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Vladimir Oltean When passed a non-head list element, list_add_tail() actually adds the new element to its left, which is what we want. Despite the slightly confusing name, use the dedicated function which does the same thing as the open-coded list_add(pos->prev). Suggested-by: Jakub Kicinski Signed-off-by: Vladimir Oltean Signed-off-by: Jakob Koschel Reviewed-by: Florian Fainelli --- drivers/net/dsa/sja1105/sja1105_vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/sja1105/sja1105_vl.c b/drivers/net/dsa/sja1105/sja1105_vl.c index e5ea8eb9ec4e..7fe9b18f1cbd 100644 --- a/drivers/net/dsa/sja1105/sja1105_vl.c +++ b/drivers/net/dsa/sja1105/sja1105_vl.c @@ -49,7 +49,7 @@ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, e->rule = rule; e->gate_state = gate_state; e->interval = entry_time; - list_add(&e->list, pos->prev); + list_add_tail(&e->list, pos); gating_cfg->num_entries++; From patchwork Wed Apr 27 16:06:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623116 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=fOg0kwuc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpNy71Tktz9s5V for ; Thu, 28 Apr 2022 02:10:23 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpNy70P32z3cfr for ; Thu, 28 Apr 2022 02:10:23 +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=fOg0kwuc; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::631; helo=mail-ej1-x631.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=fOg0kwuc; dkim-atps=neutral Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) (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 4KpNtg4dMgz3bYM for ; Thu, 28 Apr 2022 02:07:23 +1000 (AEST) Received: by mail-ej1-x631.google.com with SMTP id kq17so4379388ejb.4 for ; Wed, 27 Apr 2022 09:07:23 -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=uXZUMLY6oT5/pgJ3JE+0g8SiU8XVYCT+G02CN/YaIC8=; b=fOg0kwucAT7Z1tCyzoXxHJk7ZWXzD71f/n3w9jXO9wukuuAReuE3yVOT24ZTZv+vZm JVCT9LA60wN3RiFubbL0xNXDlmIptbiIcweT5+Iq+pQQ6rKMStHVdmh8zMziwlhhLDEp o8LUjUr464P844d7LmXXYYURuZtwf7n778EPPFFl38Vs2y7Bk3MTfaIhIp0UGGuvWsZB V0yaz+aX0zbM+kSLR5p0i1zfdWN4mxLTilWZrPILmf3nz43NVBsr/tdaBHWDSesveLIV 1IUaZlZjgjBxaddfiVtdP4ZDhvL2E1w47LgWAFMxtgcfPowPl68x/5o2vcZ6UJ411GuY 2b3w== 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=uXZUMLY6oT5/pgJ3JE+0g8SiU8XVYCT+G02CN/YaIC8=; b=O2OwvsqeYVnJmq43FCc5m2rcWBCPlK6zZQmiIsZiXY/jTcNr0WYBhgDkCNXRwVSUSU +5u+tVx/JLmqsq/LWQinpbd24EydrG6y5cDtySPsuUdtCxVUzGES3uqAuSAw28BXTJOa 64WBTB4TrG19r63a7eopC8hAjCD0Ecb5s/HKT/aw7ndVh2+yNbUEPoKNtp7i1Kx9vI8c EDO+rSoqieHkZCLS3QVzLmd5EOoZOlzXw1byOiwQL1Yb/Lka9G5LsRVyywqLoarVJjOH +MDVqRPiSjNOHqumCm9yT3hbKA9qWZjjptj5TUMMOSR13f1EoPZYzVpvOUnGJzZ4qYve yWxg== X-Gm-Message-State: AOAM532ktVLMAjBz8bmOEfsVmj5RrBhEXdtd6Z0CyGGu+CMiE7tYKZ3K lIKb7K//5CzNXGJXzOvDJ3I= X-Google-Smtp-Source: ABdhPJxJlxuNbQqjV45PE6cobcBsqISDpGtNtIgUKkVpPXa5SbB8VitgJHOwbhD0WzWZbMVXZ0mgIQ== X-Received: by 2002:a17:906:a05a:b0:6ef:a44d:2f46 with SMTP id bg26-20020a170906a05a00b006efa44d2f46mr27868498ejb.192.1651075640777; Wed, 27 Apr 2022 09:07:20 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:20 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 05/18] net: dsa: mv88e6xxx: remove redundant check in mv88e6xxx_port_vlan() Date: Wed, 27 Apr 2022 18:06:22 +0200 Message-Id: <20220427160635.420492-6-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Vladimir Oltean , Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Vladimir Oltean We know that "dev > dst->last_switch" in the "else" block. In other words, that "dev - dst->last_switch" is > 0. dsa_port_bridge_num_get(dp) can be 0, but the check "if (bridge_num + dst->last_switch != dev) continue", rewritten as "if (bridge_num != dev - dst->last_switch) continue", aka "if (bridge_num != something which cannot be 0) continue", makes it redundant to have the extra "if (!bridge_num) continue" logic, since a bridge_num of zero would have been skipped anyway. Signed-off-by: Vladimir Oltean Signed-off-by: Jakob Koschel Reviewed-by: Florian Fainelli --- drivers/net/dsa/mv88e6xxx/chip.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 64f4fdd02902..b3aa0e5bc842 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1404,9 +1404,6 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port) list_for_each_entry(dp, &dst->ports, list) { unsigned int bridge_num = dsa_port_bridge_num_get(dp); - if (!bridge_num) - continue; - if (bridge_num + dst->last_switch != dev) continue; From patchwork Wed Apr 27 16:06:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623117 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Q4jfMoI5; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpNyp55DZz9s5V for ; Thu, 28 Apr 2022 02:10:58 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpNyp48YVz3cCc for ; Thu, 28 Apr 2022 02:10:58 +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=Q4jfMoI5; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::630; helo=mail-ej1-x630.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=Q4jfMoI5; dkim-atps=neutral Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) (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 4KpNtj0fZvz3bZB for ; Thu, 28 Apr 2022 02:07:25 +1000 (AEST) Received: by mail-ej1-x630.google.com with SMTP id bv19so4363856ejb.6 for ; Wed, 27 Apr 2022 09:07:24 -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=3BKs+pBPEYltsCMoPwYgKcbwLFhDzC1Y/+CPLcIFxmM=; b=Q4jfMoI5WjWw4XYAaHu1x0te1gTTF/pJ9bwG1D3UmYTwPFRaYgjLLsbmhuhk/XZNFJ Gs8uOU1t7JXsV/V7/4dDaMLIhUoBV2frgHYjQ5lQbEgd8FcSvsvHoouafbjEK3TIVsMj +NVquu65opHryDgmkWpdBebfRUbtAI3oNqkDQInrMxRltVtO7H8w/6m0ySGIBVj+XaV7 a34xA7mMrfDVCwe1yMmIpA+jykOeQCZnIKzI15T9Z0JVYEBPoZg+21P5Xw7GptsP4b/I PW0wcWSCPNMFhaU0An6yw00SZb7MHVda9Lrhtc6dbDnC/2USs2JWfJpTjLx3K14+psKU 5rcQ== 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=3BKs+pBPEYltsCMoPwYgKcbwLFhDzC1Y/+CPLcIFxmM=; b=fgHTmYIb52TtOfTrD/lcvhvpsCFrN2ToNIGK1i9YPYBCuzrA5P/oKGPI0xZiuY3nQJ oAK15kQcN7kPfbQA+n8FckG6uSnwqbVfj40BCEOLJ30iNahfCxYgRL0IS11O6avWKAHq 8JBwxWzm6WPy0mt4geliNIBf1t44IWmrvILDGlNKRXhD1n+InNJkfI9aw0vUe/qLtP4P jgxm18nXRSleLraaEzyk/ZJ/h03u3j6OqNElp+WlxAcG/AiyOxhx9vSnhktssf9JsuRB BWw2ByRIeMapcU174WZeUiLea3mbEmdvWWyX8TfM4LAUN0uzEWCMRucDc+5iFPMhA6n8 2HFg== X-Gm-Message-State: AOAM530QlKzgr5lLv5RlcZbC2LiPQUjh3lYwq5vW7pYu3jcHQltIRMUZ mGN3BrRGt1wuIoGKfpmoxsA= X-Google-Smtp-Source: ABdhPJxeQHxPbZdIJ6XcQd2QkZ7X9v6YaYy7SDbsVYwTBp0P8/o+DdHREpRXEGzvpSxDNi7/SjRi0Q== X-Received: by 2002:a17:907:2d24:b0:6f3:91fd:db8f with SMTP id gs36-20020a1709072d2400b006f391fddb8fmr16274815ejc.150.1651075642191; Wed, 27 Apr 2022 09:07:22 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:21 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 06/18] net: dsa: mv88e6xxx: refactor mv88e6xxx_port_vlan() Date: Wed, 27 Apr 2022 18:06:23 +0200 Message-Id: <20220427160635.420492-7-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Vladimir Oltean , Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Vladimir Oltean To avoid bugs and speculative execution exploits due to type-confused pointers at the end of a list_for_each_entry() loop, one measure is to restrict code to not use the iterator variable outside the loop block. In the case of mv88e6xxx_port_vlan(), this isn't a problem, as we never let the loops exit through "natural causes" anyway, by using a "found" variable and then using the last "dp" iterator prior to the break, which is a safe thing to do. Nonetheless, with the expected new syntax, this pattern will no longer be possible. Profit off of the occasion and break the two port finding methods into smaller sub-functions. Somehow, returning a copy of the iterator pointer is still accepted. This change makes it redundant to have a "bool found", since the "dp" from mv88e6xxx_port_vlan() now holds NULL if we haven't found what we were looking for. Signed-off-by: Vladimir Oltean Signed-off-by: Jakob Koschel Reviewed-by: Florian Fainelli --- drivers/net/dsa/mv88e6xxx/chip.c | 54 ++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index b3aa0e5bc842..1f35e89053e6 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1378,42 +1378,50 @@ static int mv88e6xxx_set_mac_eee(struct dsa_switch *ds, int port, return 0; } +static struct dsa_port *mv88e6xxx_find_port(struct dsa_switch_tree *dst, + int sw_index, int port) +{ + struct dsa_port *dp; + + list_for_each_entry(dp, &dst->ports, list) + if (dp->ds->index == sw_index && dp->index == port) + return dp; + + return NULL; +} + +static struct dsa_port * +mv88e6xxx_find_port_by_bridge_num(struct dsa_switch_tree *dst, + unsigned int bridge_num) +{ + struct dsa_port *dp; + + list_for_each_entry(dp, &dst->ports, list) + if (dsa_port_bridge_num_get(dp) == bridge_num) + return dp; + + return NULL; +} + /* Mask of the local ports allowed to receive frames from a given fabric port */ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port) { struct dsa_switch *ds = chip->ds; struct dsa_switch_tree *dst = ds->dst; struct dsa_port *dp, *other_dp; - bool found = false; u16 pvlan; - /* dev is a physical switch */ if (dev <= dst->last_switch) { - list_for_each_entry(dp, &dst->ports, list) { - if (dp->ds->index == dev && dp->index == port) { - /* dp might be a DSA link or a user port, so it - * might or might not have a bridge. - * Use the "found" variable for both cases. - */ - found = true; - break; - } - } - /* dev is a virtual bridge */ + /* dev is a physical switch */ + dp = mv88e6xxx_find_port(dst, dev, port); } else { - list_for_each_entry(dp, &dst->ports, list) { - unsigned int bridge_num = dsa_port_bridge_num_get(dp); - - if (bridge_num + dst->last_switch != dev) - continue; - - found = true; - break; - } + /* dev is a virtual bridge */ + dp = mv88e6xxx_find_port_by_bridge_num(dst, + dev - dst->last_switch); } /* Prevent frames from unknown switch or virtual bridge */ - if (!found) + if (!dp) return 0; /* Frames from DSA links and CPU ports can egress any local port */ From patchwork Wed Apr 27 16:06:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623118 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=ktlHSelC; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpNzW2wSMz9s5V for ; Thu, 28 Apr 2022 02:11:35 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpNzW2485z2xlF for ; Thu, 28 Apr 2022 02:11:35 +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=ktlHSelC; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::636; helo=mail-ej1-x636.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=ktlHSelC; dkim-atps=neutral Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) (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 4KpNtk6HGzz3bdF for ; Thu, 28 Apr 2022 02:07:26 +1000 (AEST) Received: by mail-ej1-x636.google.com with SMTP id l7so4396521ejn.2 for ; Wed, 27 Apr 2022 09:07:26 -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=F5CWUEv1vjhsP5g+KRR0GTAJ+wUhkJAp7IXSJfTRMkw=; b=ktlHSelCUdklQ1hSXzFqDWqmG9X1pagBePVGyp1NoHlyisKtGYRGKxHG0NbsK9ea2F bhUDjmLPsJix5VWIrG0R6YVTR0iVf7pKs5UKcBwfinw7buQ2xfs2xgXnxjP5uHwH1Fh5 031mQadxuy5wGLM7giP9IvPldFIqfXRNx2GcDZTenUfBHGcZUgyT+r+hd3BqcVI4j9t4 hA70ebcnZB/TVpR0t4sXya7kC/hDNsgNpQN45hCTVEIOJK0tJbe469jj+Ud6VdJnMayZ xGRq0JTxwhSO1bgIPan3wYqGsmhT3lH5TWc/hgRLeKyPzXBoXJJeUQtDzj9W3tyroZne 6WBA== 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=F5CWUEv1vjhsP5g+KRR0GTAJ+wUhkJAp7IXSJfTRMkw=; b=245ljFOcK4bX9VP9+A9a3D1ngL6frQzTxV1ZAFIZRuk4NTfKuRfFAv84v91tbSZa/s qcuatUqtJT/K7gYtzCJOzznE6jp3L5RW+wBsQbo+IIdjKiAhTWBLLz178XBQymbGSB0z 2Zqm6qkj0Yxhnvd16moElKRSM4TRSwxnCwUDO1j9BZiIopR6GGiXQVp2DD/nV2kUtakb yV4NvrDCXUuXQ7zxTmplcAvJMoKrkoHS2H+MeLa2tjNW9G09shHO/2knx9tIJN3ccWP9 N2bGCvCOG7dZzyVKlDz2RfaWERqbg10kW+gMq2R8gY9v4ThjmH/MYBdWGifN8BvvvygR E0/A== X-Gm-Message-State: AOAM533+zKlK+rBQUJ2uPnFZ7I8YSDONB38Sb9VoY9GN6q0CRLcA9DFo vtuXFilH9zZQBG+eRaPWwVw= X-Google-Smtp-Source: ABdhPJyurPa9HKBRwXWzgBxCXBgmg7VG+zuYm1075t+N+Dlk6AGeeP2bXD9LJOaRPq4H7qfCukLjOQ== X-Received: by 2002:a17:907:c1e:b0:6f3:97f3:cb6b with SMTP id ga30-20020a1709070c1e00b006f397f3cb6bmr14922818ejc.80.1651075643582; Wed, 27 Apr 2022 09:07:23 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:23 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 07/18] net: dsa: Replace usage of found with dedicated list iterator variable Date: Wed, 27 Apr 2022 18:06:24 +0200 Message-Id: <20220427160635.420492-8-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 instead of a found boolean [1]. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel Reviewed-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- net/dsa/dsa.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 89c6c86e746f..645522c4dd4a 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -112,22 +112,21 @@ const struct dsa_device_ops *dsa_find_tagger_by_name(const char *buf) const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol) { - struct dsa_tag_driver *dsa_tag_driver; + struct dsa_tag_driver *dsa_tag_driver = NULL, *iter; const struct dsa_device_ops *ops; - bool found = false; request_module("%s%d", DSA_TAG_DRIVER_ALIAS, tag_protocol); mutex_lock(&dsa_tag_drivers_lock); - list_for_each_entry(dsa_tag_driver, &dsa_tag_drivers_list, list) { - ops = dsa_tag_driver->ops; + list_for_each_entry(iter, &dsa_tag_drivers_list, list) { + ops = iter->ops; if (ops->proto == tag_protocol) { - found = true; + dsa_tag_driver = iter; break; } } - if (found) { + if (dsa_tag_driver) { if (!try_module_get(dsa_tag_driver->owner)) ops = ERR_PTR(-ENOPROTOOPT); } else { From patchwork Wed Apr 27 16:06:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623120 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=NcCauSE8; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpP0K6R3gz9s5V for ; Thu, 28 Apr 2022 02:12:17 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpP0K5SFYz3cLr for ; Thu, 28 Apr 2022 02:12:17 +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=NcCauSE8; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::62e; helo=mail-ej1-x62e.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=NcCauSE8; dkim-atps=neutral Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) (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 4KpNtm26Lwz3bgQ for ; Thu, 28 Apr 2022 02:07:28 +1000 (AEST) Received: by mail-ej1-x62e.google.com with SMTP id l7so4396641ejn.2 for ; Wed, 27 Apr 2022 09:07:28 -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=7YEqjlB8bsXZ45gzNCMwH2JxmTxm4dwtRKumhhyyThw=; b=NcCauSE8guQ5PDo196E3N9DO9XpnNC2xfsV8gl7F4q0FqDFH8aXc0GMoMnUrVoGxW2 SPkhjIb41OJqLMeNhVK79tU46Be4awGFHY6bM2tg+HfPbx8aTqAqnWieQUrRfEkAWODP yuw8sUya5Vyaqi/5ktMKe177eRlQRmVgzXXr+pbLw+MZq/EW3xuB0Fhr3QMBGyl0fk6o VVZOYwqdDntviK5fIHhMCHIPsISCYT6DlNfIH2vUB75sscfAKdSTn9wZO8SDid/2va9W Za+9rfsvaDii9tUUg3CYkpp1FWb1SbW6EjloCCRxltPJGpCoTunnPik/5bbdGEOzYiGy ejmg== 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=7YEqjlB8bsXZ45gzNCMwH2JxmTxm4dwtRKumhhyyThw=; b=WUYA2eBTjv6ScC/REskSpxChzKRlV/VDNoZisxXHv3vG36e0BXMrzEVVAfSBFgA8lM iRbscqQN5txG6+esGRzr36g8Ytu34G1gxKuwxk/WibA2KVxmvn8/4lU3kMciTajcfDrJ rTa0RFdpVoHykrtZO+Nm1cjRTf6jppvy3iUnffxV8Q0iQQEGX+Xn7TWVXnLgR1+Amzzq Azo8oRncU7Dp06+H+6ViQsKrRlk1UQqDF2bHqUbsQ0fUHp653ywN3e8dn/bUx1Jm5Lpk 0lwPYKrazkWngvNIW+dcmCJp0HssBdMsYQ1Yw2cgIqRE6jiJLHsYvhNL0jnqo3P7oMc4 ReCA== X-Gm-Message-State: AOAM530cFjXXc4ZO0AIqjr5mehJy0tm2MoV77o/IMQqQgu38LwHJBgFq VoBB85TBEanzshT54tOpvZ4= X-Google-Smtp-Source: ABdhPJzWTvvEzfF9Mo03ftd31+mX2wj55MlxQnmpjYa3HALMm0ulXcZJQo9QvW/KfybMA6V23ex34Q== X-Received: by 2002:a17:907:3f13:b0:6f3:ad46:be1f with SMTP id hq19-20020a1709073f1300b006f3ad46be1fmr9676404ejc.627.1651075644951; Wed, 27 Apr 2022 09:07:24 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:24 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 08/18] net: sparx5: Replace usage of found with dedicated list iterator variable Date: Wed, 27 Apr 2022 18:06:25 +0200 Message-Id: <20220427160635.420492-9-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 instead of a found boolean [1]. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- .../microchip/sparx5/sparx5_mactable.c | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c index a5837dbe0c7e..bb8d9ce79ac2 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c @@ -362,8 +362,7 @@ static void sparx5_mact_handle_entry(struct sparx5 *sparx5, unsigned char mac[ETH_ALEN], u16 vid, u32 cfg2) { - struct sparx5_mact_entry *mact_entry; - bool found = false; + struct sparx5_mact_entry *mact_entry = NULL, *iter; u16 port; if (LRN_MAC_ACCESS_CFG_2_MAC_ENTRY_ADDR_TYPE_GET(cfg2) != @@ -378,28 +377,28 @@ static void sparx5_mact_handle_entry(struct sparx5 *sparx5, return; mutex_lock(&sparx5->mact_lock); - list_for_each_entry(mact_entry, &sparx5->mact_entries, list) { - if (mact_entry->vid == vid && - ether_addr_equal(mac, mact_entry->mac)) { - found = true; - mact_entry->flags |= MAC_ENT_ALIVE; - if (mact_entry->port != port) { + list_for_each_entry(iter, &sparx5->mact_entries, list) { + if (iter->vid == vid && + ether_addr_equal(mac, iter->mac)) { + iter->flags |= MAC_ENT_ALIVE; + if (iter->port != port) { dev_warn(sparx5->dev, "Entry move: %d -> %d\n", - mact_entry->port, port); - mact_entry->port = port; - mact_entry->flags |= MAC_ENT_MOVED; + iter->port, port); + iter->port = port; + iter->flags |= MAC_ENT_MOVED; } /* Entry handled */ + mact_entry = iter; break; } } mutex_unlock(&sparx5->mact_lock); - if (found && !(mact_entry->flags & MAC_ENT_MOVED)) + if (mact_entry && !(mact_entry->flags & MAC_ENT_MOVED)) /* Present, not moved */ return; - if (!found) { + if (!mact_entry) { /* Entry not found - now add */ mact_entry = alloc_mact_entry(sparx5, mac, vid, port); if (!mact_entry) From patchwork Wed Apr 27 16:06:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623122 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=FMGbpYNN; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpP1301kqz9s5V for ; Thu, 28 Apr 2022 02:12:54 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpP125xpFz3c85 for ; Thu, 28 Apr 2022 02:12:54 +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=FMGbpYNN; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::630; helo=mail-ej1-x630.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=FMGbpYNN; dkim-atps=neutral Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) (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 4KpNtn0ZWXz3bhQ for ; Thu, 28 Apr 2022 02:07:29 +1000 (AEST) Received: by mail-ej1-x630.google.com with SMTP id i27so4345522ejd.9 for ; Wed, 27 Apr 2022 09:07:28 -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=f1NofSwJuKbiTcVP4Eyds36Vn/5/VoS2zfBkRtVaGBU=; b=FMGbpYNN25F29l+OAZ0oU2BSV4UFQJQ8hALv0efMdnT1md03Ok8yKVBi1uKWmXTXYr 8a9N8bN4djVpu+rhkHyFNvsW7gx582gKpIIKhML+MK8K+3O12xCutoBlK02J44kqEg9p FxMeGTrpDvinkZIEnIngkY0Q7JkNGcaS/bxLY5uu2ICywIuSjpgLHl0VL7EiP7CCymSZ sSn5E8X+YJyjuSjXYZ8D0DrNxo/9SZLC9+ii96+bsyqSnU7Ed9OH5SSGM/QEiT4TSXyM rkSYO4NHWuqn73Ql8mLCthpWscg4aPdcFDI2cCxtAKq7gLV4kgH6rvuF/haYkBEgILrA faaA== 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=f1NofSwJuKbiTcVP4Eyds36Vn/5/VoS2zfBkRtVaGBU=; b=y7gW46BD4zRunumb4qks8Mi7GEpOhmHTYaJ5JtNY2XqFehkyf5v3N4QpK7KHWrUlmY JMjDnPbVArSgJ3DheXECr8nTt2NFO0aLln1pLZr/XL+XyX6xC+C2fNqKBMo+PvMi1KMK FSJFldjRaQrURoK3mnH4MZpXjYuOgHV2ZB6MjEaEvCSi64Z19k7FTbzjBUW8dENfAR69 FD3u5H6r6fuPNslOnEYuv+icLGiNrX9G3XEUyMkEfRiCQgmzH3d8CbueZRsrqot4U74y m+BU3HxOyLQLHn1rciD+g+I9K+gB7+6MIJbBHgRIN9Y0RkFURfdyNLgESd8ATiH51/m4 EMYQ== X-Gm-Message-State: AOAM530yFbjMzLbbz5y2MQu6wIdd3xPF3IuwdIW0ThM4DcHXbeF8Mot+ JOeOvp+fQpHpOCnxCyjGM5E= X-Google-Smtp-Source: ABdhPJwIhJiLJw69ilI7ZBKSX+zC1iXAarfAnk0c8Ge8xoFbIVAxNWeUGJZz0HlsPZ83L0cvGrZ8xQ== X-Received: by 2002:a17:907:c0c:b0:6f3:8667:9be4 with SMTP id ga12-20020a1709070c0c00b006f386679be4mr18859070ejc.325.1651075646215; Wed, 27 Apr 2022 09:07:26 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:25 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 09/18] qed: Use dedicated list iterator variable Date: Wed, 27 Apr 2022 18:06:26 +0200 Message-Id: <20220427160635.420492-10-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- drivers/net/ethernet/qlogic/qed/qed_dev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qed/qed_dev.c b/drivers/net/ethernet/qlogic/qed/qed_dev.c index 672480c9d195..e920e7dcf66a 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_dev.c +++ b/drivers/net/ethernet/qlogic/qed/qed_dev.c @@ -174,7 +174,7 @@ int qed_db_recovery_add(struct qed_dev *cdev, int qed_db_recovery_del(struct qed_dev *cdev, void __iomem *db_addr, void *db_data) { - struct qed_db_recovery_entry *db_entry = NULL; + struct qed_db_recovery_entry *db_entry = NULL, *iter; struct qed_hwfn *p_hwfn; int rc = -EINVAL; @@ -190,12 +190,13 @@ int qed_db_recovery_del(struct qed_dev *cdev, /* Protect the list */ spin_lock_bh(&p_hwfn->db_recovery_info.lock); - list_for_each_entry(db_entry, + list_for_each_entry(iter, &p_hwfn->db_recovery_info.list, list_entry) { /* search according to db_data addr since db_addr is not unique (roce) */ - if (db_entry->db_data == db_data) { - qed_db_recovery_dp_entry(p_hwfn, db_entry, "Deleting"); - list_del(&db_entry->list_entry); + if (iter->db_data == db_data) { + qed_db_recovery_dp_entry(p_hwfn, iter, "Deleting"); + list_del(&iter->list_entry); + db_entry = iter; rc = 0; break; } From patchwork Wed Apr 27 16:06:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623123 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=dydbqc5J; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpP1k4y9yz9s5V for ; Thu, 28 Apr 2022 02:13:30 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpP1k2Kb4z3f0J for ; Thu, 28 Apr 2022 02:13:30 +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=dydbqc5J; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::629; helo=mail-ej1-x629.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=dydbqc5J; dkim-atps=neutral Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) (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 4KpNtp6r8Dz3bp3 for ; Thu, 28 Apr 2022 02:07:30 +1000 (AEST) Received: by mail-ej1-x629.google.com with SMTP id i27so4345665ejd.9 for ; Wed, 27 Apr 2022 09:07:30 -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=LXuHnml0JyQ7WUWtSyqxCdcrvdOAihH7ECEcB+ac3FQ=; b=dydbqc5J60BLLi30zbMUbH7rkOREmVuwqXYM7KqyVJ5PTePK07uL1it2F3ppOULrQp XOnGBiUiY9fCOnKmRENfByrA63YlpbGpanCw0uQnd+ZXKWb23Fe+VUM+HBSvz3hbwYb0 fxxJkdmou9OPPb6NqqihMEGz7guVzyP7lwViOWdEg5SiEssRFwqsPO1dwSNHPc6DCXEQ WAwUQSN/dMR6z/a2sieXWO8H3XWqgFIVTl5X+QYo6IQ1GO4xbn9k1OYHY55/FLUVZJaQ unv/NKd2hSzV1Yo9IFcRabSOEMNPfdQuZFplMoMO96GBvThfkSmcQUo5mcHy0G6nPCHE 39gA== 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=LXuHnml0JyQ7WUWtSyqxCdcrvdOAihH7ECEcB+ac3FQ=; b=YOycCRgl/C7znI7OAcbPpwWPRfUc2mJA19VvvtJEks6fy8CarjKjltiyuSaguFbf3c lxr2OOtalaoxDkZ3mzp+94S164uww26j1EeypCiReSUG9gte6pjFf2QqLAFp4HZvPuXe qJVSncW3+tw9D2G1ReBZOohF+gN9W9rh2iIW5bu2rLWCUxs8DFsq0avEnSZXJ0tB60JI I88x6wf5SDmaGYNSTIJVaQnw+BacYRZdEk4WJlW7/PEKQQc0E8D8FlUy4VTpLbh0Nl6G 7ekb6cZldgKBBiR3B8WYKKeOOVoUOdDukPJl5SKAEqq50erbtfrRMbmZ3DrhrqW+97dC ddbw== X-Gm-Message-State: AOAM5321quN+6snLqkW7Y2lMmdLZvvSQ/OnABTYqx2lbDjPkjTdcO3uO DvEfFnbYMEVy00LxRZKTliU= X-Google-Smtp-Source: ABdhPJy3vcafoHiVPbX6lh1POBOoAQAfG6usQdpjwle19kzFa7yL07Q0av8Z+KNsAtfAW8A2iujkhw== X-Received: by 2002:a17:907:3f02:b0:6f3:5c42:321a with SMTP id hq2-20020a1709073f0200b006f35c42321amr25692644ejc.521.1651075647581; Wed, 27 Apr 2022 09:07:27 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:27 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 10/18] qed: Replace usage of found with dedicated list iterator variable Date: Wed, 27 Apr 2022 18:06:27 +0200 Message-Id: <20220427160635.420492-11-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 instead of a found boolean [1]. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- drivers/net/ethernet/qlogic/qed/qed_iwarp.c | 26 ++++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qed/qed_iwarp.c b/drivers/net/ethernet/qlogic/qed/qed_iwarp.c index 1d1d4caad680..198c9321bf51 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_iwarp.c +++ b/drivers/net/ethernet/qlogic/qed/qed_iwarp.c @@ -1630,38 +1630,36 @@ static struct qed_iwarp_listener * qed_iwarp_get_listener(struct qed_hwfn *p_hwfn, struct qed_iwarp_cm_info *cm_info) { - struct qed_iwarp_listener *listener = NULL; + struct qed_iwarp_listener *listener = NULL, *iter; static const u32 ip_zero[4] = { 0, 0, 0, 0 }; - bool found = false; - list_for_each_entry(listener, + list_for_each_entry(iter, &p_hwfn->p_rdma_info->iwarp.listen_list, list_entry) { - if (listener->port == cm_info->local_port) { - if (!memcmp(listener->ip_addr, + if (iter->port == cm_info->local_port) { + if (!memcmp(iter->ip_addr, ip_zero, sizeof(ip_zero))) { - found = true; + listener = iter; break; } - if (!memcmp(listener->ip_addr, + if (!memcmp(iter->ip_addr, cm_info->local_ip, sizeof(cm_info->local_ip)) && - (listener->vlan == cm_info->vlan)) { - found = true; + iter->vlan == cm_info->vlan) { + listener = iter; break; } } } - if (found) { + if (listener) DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener found = %p\n", listener); - return listener; - } + else + DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener not found\n"); - DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener not found\n"); - return NULL; + return listener; } static int From patchwork Wed Apr 27 16:06:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623127 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=P7ArfueF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpP2Y5KH1z9s5V for ; Thu, 28 Apr 2022 02:14:13 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpP2Y4PPbz3cgt for ; Thu, 28 Apr 2022 02:14:13 +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=P7ArfueF; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::631; helo=mail-ej1-x631.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=P7ArfueF; dkim-atps=neutral Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) (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 4KpNtq56zfz3bpQ for ; Thu, 28 Apr 2022 02:07:31 +1000 (AEST) Received: by mail-ej1-x631.google.com with SMTP id i27so4345787ejd.9 for ; Wed, 27 Apr 2022 09:07:31 -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=JrLemglUST4WORuuuukktAwV8TRd9yLyGflAl3xl1zc=; b=P7ArfueFfqb+nsrBlYp2Z856X99lZCDM/QPiYaspWe/aoZAfnFhi0ej7wLBT4hCcfL 77k4+v50MSgxLOvjNPnIhYfOBW4FQFYVlZiYujNH+pqRygBvfUrRQ3FV/jFtqBJKS/2b Lx93egMHRueiT7MNxTOXGno/PUsnNMD3V7O++/DXMseaGxU16Wm96460Dus2hzo+sGA0 +bJ6hDMpHDm4BqEA3s2WCFCDC6qlZiwzBTRuauQoibdYSZYp81HTcc3V4uhwItLxrziD VaUpGDXAGkwEXQIB658hbO3HrqsFXij7V0DZUhMsQ5/sihqgnJtuLyZupaLA8yDcY1MF Xbug== 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=JrLemglUST4WORuuuukktAwV8TRd9yLyGflAl3xl1zc=; b=Do6lvyY66MXaDGPs+FRR6DIvYxJaS9Houqekw+w6waAsQb8pyHKRCEffnP76oLD4ew olxtk+Fzr0JdssXOc0cQWSYjY36p8iJUJEBGO1qY0SCnncB6EYnZn2N8D0SQawiLPKye O2CHG06TLxn+/oMOajxZtJ4P6j8GQZ84UWuD/l5kfyEZTPuXchCeq6oLarjsjHVJu9da S5zkZoOPn4Yos2nr7g/E/xndqyt6/68+PpgECNktuEPfbot5yFosJ4Nuik4sDjoJ9Jj1 Wvzc3j66fK0ivdDIjko9VxrcU3E7LZxli3RmcBuqQYjmhM1nu3/ZUrzuPoWBDQJYzqxo b8lA== X-Gm-Message-State: AOAM5338odxJOLRh09I0CDBgLW9tcgfSGirOBn8JT4dZUx247Vq+MUho EaVL5AI8Cx1vt3s6XBvWOGA= X-Google-Smtp-Source: ABdhPJymUyAuP9S3z9f8SGZ0ibdaRIW+1KvXVMPgBEGCfB3jsk37oMAvhNa2911ZCug37bA6orWp7w== X-Received: by 2002:a17:907:97cd:b0:6f3:aeb8:6002 with SMTP id js13-20020a17090797cd00b006f3aeb86002mr9157397ejc.530.1651075648894; Wed, 27 Apr 2022 09:07:28 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:28 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 11/18] qed: Remove usage of list iterator variable after the loop Date: Wed, 27 Apr 2022 18:06:28 +0200 Message-Id: <20220427160635.420492-12-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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. Since "found" and "p_ent" need to be equal, "found" should be used consistently to limit the scope of "p_ent" to the list traversal in the future. Signed-off-by: Jakob Koschel --- drivers/net/ethernet/qlogic/qed/qed_spq.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qed/qed_spq.c b/drivers/net/ethernet/qlogic/qed/qed_spq.c index d01b9245f811..cbaa2abed660 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_spq.c +++ b/drivers/net/ethernet/qlogic/qed/qed_spq.c @@ -934,10 +934,10 @@ int qed_spq_completion(struct qed_hwfn *p_hwfn, u8 fw_return_code, union event_ring_data *p_data) { + struct qed_spq_entry *found = NULL; struct qed_spq *p_spq; - struct qed_spq_entry *p_ent = NULL; + struct qed_spq_entry *p_ent; struct qed_spq_entry *tmp; - struct qed_spq_entry *found = NULL; if (!p_hwfn) return -EINVAL; @@ -980,7 +980,7 @@ int qed_spq_completion(struct qed_hwfn *p_hwfn, DP_VERBOSE(p_hwfn, QED_MSG_SPQ, "Complete EQE [echo %04x]: func %p cookie %p)\n", le16_to_cpu(echo), - p_ent->comp_cb.function, p_ent->comp_cb.cookie); + found->comp_cb.function, found->comp_cb.cookie); if (found->comp_cb.function) found->comp_cb.function(p_hwfn, found->comp_cb.cookie, p_data, fw_return_code); From patchwork Wed Apr 27 16:06:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623128 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=iYefV4x4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpP3F6Z3Fz9s5V for ; Thu, 28 Apr 2022 02:14:49 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpP3F3bJTz3cfv for ; Thu, 28 Apr 2022 02:14:49 +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=iYefV4x4; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::633; helo=mail-ej1-x633.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=iYefV4x4; dkim-atps=neutral Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) (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 4KpNts4CK1z3bmV for ; Thu, 28 Apr 2022 02:07:33 +1000 (AEST) Received: by mail-ej1-x633.google.com with SMTP id m20so4328732ejj.10 for ; Wed, 27 Apr 2022 09:07:33 -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=0WZ3VKnVxGM80qdLHkweZkrBfRptzeVUXSKm7/OGDn8=; b=iYefV4x4cS2P5G6zvG61cBj8T2py/pIo/pjs0Q9iTwQdWI8zdKVZ+iw8xHm0OF578N Uzt26JvfjZUW2E1xhbuyxsNYSzvthUBdnuF7xbo5yMRhTPUU4f4qkkZKiTb7iQaf/WhB /NVvWxQ9VRsNlqNb2A8Lm2FeT/6uTp7jNqoJFVbdG6i7s68Fxz+UPfFnm2U+cuBS/lO0 YzSgsu0XtaWbRV9GWi9ix5UU4FqVq6EGD6xZu53Wc6vh7oEaiIDzsI1ZtAezpWGlAJ6Y gdmp7zSN6Cik+iMJNUTOlzUx56lUG//1VO4MJDNdjOhY5M5juk1C594Gn81ZHlvaE9IO Zppw== 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=0WZ3VKnVxGM80qdLHkweZkrBfRptzeVUXSKm7/OGDn8=; b=3urZJBhcrMk4ukj/eqjdEfeOZzGFt5glY52DA5fv5Xf6z1PADLP82XiI7zmFwzfR/U 12GkRtrRhSbLHaeuttjU6gYITxKvpCEuWHZRWkCmq23dzGmoPwYCQG9t8TO1+4ApKZdS YhD5Plb87uLC3KCz4GQw54DscJxl1JkYPPAWXWUkMV+9woHq3SKxv2G3NnXpYf8w8t4B Nwt7qcTny8Ruuo44yCX9/TIj7DFxiOjd+m1JjrIzPbQHQ1gR4OH+h7AovQOlkdeUJbvs r5p6PqvwqPxOxAOV5n1z3ohZJwzKSMA9e0OwZ4CQARLUlQYea8CxGNsbI8Qp2uDeK6zT HwJA== X-Gm-Message-State: AOAM530m7rRhxlLTaVCUQxZBsSbTkCYBVmUJ/ESbuFzfQM4Fph6jtbCR mS7IVtYTkH2xiRkOjsll7+Q= X-Google-Smtp-Source: ABdhPJzxkWZJssycANRkME55YZz1X8TDc5voDlGllps54WeGD9LALQXZ3eiyQ26eO0/xVC/EDO0p3g== X-Received: by 2002:a17:907:7ba3:b0:6ef:f9ca:f2da with SMTP id ne35-20020a1709077ba300b006eff9caf2damr16508279ejc.634.1651075650148; Wed, 27 Apr 2022 09:07:30 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:29 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 12/18] net: qede: Replace usage of found with dedicated list iterator variable Date: Wed, 27 Apr 2022 18:06:29 +0200 Message-Id: <20220427160635.420492-13-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 instead of a found boolean [1]. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- drivers/net/ethernet/qlogic/qede/qede_rdma.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qede/qede_rdma.c b/drivers/net/ethernet/qlogic/qede/qede_rdma.c index 6304514a6f2c..2eb03ffe2484 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_rdma.c +++ b/drivers/net/ethernet/qlogic/qede/qede_rdma.c @@ -246,18 +246,17 @@ static void qede_rdma_change_mtu(struct qede_dev *edev) static struct qede_rdma_event_work * qede_rdma_get_free_event_node(struct qede_dev *edev) { - struct qede_rdma_event_work *event_node = NULL; - bool found = false; + struct qede_rdma_event_work *event_node = NULL, *iter; - list_for_each_entry(event_node, &edev->rdma_info.rdma_event_list, + list_for_each_entry(iter, &edev->rdma_info.rdma_event_list, list) { - if (!work_pending(&event_node->work)) { - found = true; + if (!work_pending(&iter->work)) { + event_node = iter; break; } } - if (!found) { + if (!event_node) { event_node = kzalloc(sizeof(*event_node), GFP_ATOMIC); if (!event_node) { DP_NOTICE(edev, From patchwork Wed Apr 27 16:06:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623133 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Loswq8nv; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpP425Rw8z9s5V for ; Thu, 28 Apr 2022 02:15:30 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpP424dwDz3f7K for ; Thu, 28 Apr 2022 02:15:30 +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=Loswq8nv; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::531; helo=mail-ed1-x531.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=Loswq8nv; dkim-atps=neutral Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (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 4KpNtv0817z3bfc for ; Thu, 28 Apr 2022 02:07:34 +1000 (AEST) Received: by mail-ed1-x531.google.com with SMTP id z99so2504829ede.5 for ; Wed, 27 Apr 2022 09:07:34 -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=fIZenjsGtzoZOCvRY/8dIr7NFNGibTLVVWT+oNYuIJo=; b=Loswq8nvbzRxDR73WmbwfNXIJGBqOC3T+Wyo24t48yxcjf//w0mo3l9Ym0uXu/cZ9A Y22QBny9+t/M8zNI4cf7TfXze/2AggxqotMTFurZBhCPTYEO2+h9g9aiR/eJVXoKwegL cjrR3bUQtRNgySrtOaBt9/Kf1FfoMlTT01nygxeQrimJB/zoCEAs2Emyt1RSc7c51bGm Z7yuYGjT5B3iX0wv12wvEt2tcr2W+BQbB3Xp5mHBBe4BLBGoJ0tFH7b5ACm6jH9qYL7M OSkvFVGEotQRL9Ne9eyhT7HWSsrS8qbM4eeLpI4OETGfcXP84f0qR8TqMxbhiHkvmY2B jEhw== 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=fIZenjsGtzoZOCvRY/8dIr7NFNGibTLVVWT+oNYuIJo=; b=gjS+ZM7PRbkYbkfMoB+9KnGG7/40o/1KIJnIUuPvB+PMl87hILl5SiVO9gNc+KvdDq wdcuVO2ZHf+crm0ENwHY9YctoEwP5iCeBUdpjyUpJij1wl/gB9XIBRAyPpMV7xM0wt9o CNJeqVBEzkf/tkNZw6StrTIDtY7xLnR4fk/EQFTWbrqAbfPacSojXq7AnV4iK0N2Cvwu b6t20cqOX7LgYEiPMNqhXybYSy1UV3b0IZl2w15zwO7HSgTG+m5FJVeQYYPPZ6JHNdRb pJ05pPAHLeV5yOcgc+jHCl36vqdyVdaMgp1u8ovqix9BWR+WE+rlquQZn85sdd6bxh75 rG7w== X-Gm-Message-State: AOAM532E7q3pJWRZ8l140uP+uY6mWHx5dGYzMIPJ+Qj/wSC5BpjQ/3xH V0uvxSOyEgQwPlWVk4rQofA= X-Google-Smtp-Source: ABdhPJycm/m7LkEc21AKXttuikHx7Z81DgO8aTXJSz0bAgx9hTWZ3Wde84ZzMxbdpyXArZqhFoaUAA== X-Received: by 2002:aa7:d393:0:b0:425:a8f8:663a with SMTP id x19-20020aa7d393000000b00425a8f8663amr30810362edq.323.1651075651612; Wed, 27 Apr 2022 09:07:31 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:31 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 13/18] net: qede: Remove check of list iterator against head past the loop body Date: Wed, 27 Apr 2022 18:06:30 +0200 Message-Id: <20220427160635.420492-14-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" When list_for_each_entry() completes the iteration over the whole list without breaking the loop, the iterator value will be a bogus pointer computed based on the head element. While it is safe to use the pointer to determine if it was computed based on the head element, either with list_entry_is_head() or &pos->member == head, using the iterator variable after the loop should be avoided. 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]. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- drivers/net/ethernet/qlogic/qede/qede_filter.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qede/qede_filter.c b/drivers/net/ethernet/qlogic/qede/qede_filter.c index 3010833ddde3..3d167e37e654 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_filter.c +++ b/drivers/net/ethernet/qlogic/qede/qede_filter.c @@ -829,18 +829,21 @@ int qede_configure_vlan_filters(struct qede_dev *edev) int qede_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid) { struct qede_dev *edev = netdev_priv(dev); - struct qede_vlan *vlan; + struct qede_vlan *vlan = NULL; + struct qede_vlan *iter; int rc = 0; DP_VERBOSE(edev, NETIF_MSG_IFDOWN, "Removing vlan 0x%04x\n", vid); /* Find whether entry exists */ __qede_lock(edev); - list_for_each_entry(vlan, &edev->vlan_list, list) - if (vlan->vid == vid) + list_for_each_entry(iter, &edev->vlan_list, list) + if (iter->vid == vid) { + vlan = iter; break; + } - if (list_entry_is_head(vlan, &edev->vlan_list, list)) { + if (!vlan) { DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN), "Vlan isn't configured\n"); goto out; From patchwork Wed Apr 27 16:06:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623134 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Hkxy0IEK; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpP4l066jz9s5V for ; Thu, 28 Apr 2022 02:16:06 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpP4k4YD7z3cBT for ; Thu, 28 Apr 2022 02:16:06 +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=Hkxy0IEK; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::634; helo=mail-ej1-x634.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=Hkxy0IEK; dkim-atps=neutral Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) (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 4KpNtx47qrz3bbb for ; Thu, 28 Apr 2022 02:07:37 +1000 (AEST) Received: by mail-ej1-x634.google.com with SMTP id g6so4402393ejw.1 for ; Wed, 27 Apr 2022 09:07:37 -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=V+mtTmsePMUlrvbA5Gxvy5O64p/39QZZ8B6LTk09adM=; b=Hkxy0IEKCInDQhIHwWszLgmHYH27wUiu5nhfHuSds0ny6zxcsjzJuFYvcasAraAcXK XharPWt16KsV4QDb7JrdvuM+8RmU4T647/y4Q7CWjLDD3mAEnFszewgn03OsKGZqTGdZ dtOQrwcZI0OESJSOMYKI2hNrmU3D7pbiUhKIbTR4NH+J1DfH4RABBaFqwCQIYrJsN1if YK4UXm1CsKw+Ez+Pa7EFZlXghqP7Pn9WA+VKpmdLvuXvhIgkfSips9y75xTHfdoIGsty RcwT9fu+KvxsSkFr+hi488HDN0jqDbibcol5pUUb1ymbFcQ9cJxycGmwzR0BEKkWZSDO uidA== 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=V+mtTmsePMUlrvbA5Gxvy5O64p/39QZZ8B6LTk09adM=; b=vbEolTFwNI0PwW4qc4Ju36dS8emzLOqd3yJ5jvT4UE+8rICzBRXSvB/38ddhznvKEI GqEYVgOyFOd7uO4UTNCr2asG33hHwbdZpJq4l+p6ytgLhfZJcUIgrO2YAn+0P58SnKSh v7ArEydHT8bDPDW9LvIVAQwl+OX1SyaV7a1CTGjBVMVvzFC5UqjY2HKr+bqHKV3D0Ugu ZryFpKPKA6i8q4iqR8HWzycsiM/DuJgUKRCxLCZhCPNPsjvkE0NaTb96fgzMfYFxelgR bpeCif3+f6yz6WxwwZ5x2wJ+6SA5Stg1uQHAyDCGf2pS7FnoD2FwgCg1PMzxSYznAqav 3DFQ== X-Gm-Message-State: AOAM5326uTt/1FCoskHCZWF4bJvdD3ejrispzskf9cifk+3ZuSRsfdFM d2lzOYIiUh+DLK459SmQWKQ= X-Google-Smtp-Source: ABdhPJzxa9+NcJtLVPAcuSDhYJGek9dFCba/k1LpR14Atj5Kkk4JNNCxTqiszf04IOdTXlAqnpMKBQ== X-Received: by 2002:a17:907:3e92:b0:6f3:8ff4:66b2 with SMTP id hs18-20020a1709073e9200b006f38ff466b2mr16219496ejc.697.1651075653001; Wed, 27 Apr 2022 09:07:33 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:32 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 14/18] sfc: Remove usage of list iterator for list_add() after the loop body Date: Wed, 27 Apr 2022 18:06:31 +0200 Message-Id: <20220427160635.420492-15-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.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 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 &new->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/sfc/rx_common.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/sfc/rx_common.c b/drivers/net/ethernet/sfc/rx_common.c index fa8b9aacca11..74c056210e0b 100644 --- a/drivers/net/ethernet/sfc/rx_common.c +++ b/drivers/net/ethernet/sfc/rx_common.c @@ -560,14 +560,17 @@ struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx) { struct list_head *head = &efx->rss_context.list; struct efx_rss_context *ctx, *new; + struct list_head *pos = head; u32 id = 1; /* Don't use zero, that refers to the master RSS context */ WARN_ON(!mutex_is_locked(&efx->rss_lock)); /* Search for first gap in the numbering */ list_for_each_entry(ctx, head, list) { - if (ctx->user_id != id) + if (ctx->user_id != id) { + pos = &ctx->list; break; + } id++; /* Check for wrap. If this happens, we have nearly 2^32 * allocated RSS contexts, which seems unlikely. @@ -585,7 +588,7 @@ struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx) /* Insert the new entry into the gap */ new->user_id = id; - list_add_tail(&new->list, &ctx->list); + list_add_tail(&new->list, pos); return new; } From patchwork Wed Apr 27 16:06:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623135 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=ggGv5P+E; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpP5R1hdHz9s5V for ; Thu, 28 Apr 2022 02:16:43 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpP5R0cyqz3dqh for ; Thu, 28 Apr 2022 02:16:43 +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=ggGv5P+E; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::62f; helo=mail-ej1-x62f.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=ggGv5P+E; dkim-atps=neutral Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (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 4KpNtx73XVz3bgV for ; Thu, 28 Apr 2022 02:07:37 +1000 (AEST) Received: by mail-ej1-x62f.google.com with SMTP id y3so4326978ejo.12 for ; Wed, 27 Apr 2022 09:07:37 -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=ggGv5P+EjcqZAl8voak+pwbzxzcjAmNNNxozwigeVhgulY+Vg7Hr8WKASQPrdbJxaK iNx74FS82CGgZTJVRSG4Oomayax8Ix2G83dwD/ChqX7H3+drsjBoiyv5lCzqeyuioEaS XBD5wk28Byq9pX2aiPXMyH6LlS/LvHPJDThnFQKgh3nlde4cQ2ah/HtfA3uKG+KOtjGk xhzjAAKQPnpbxT1RB3eO/pkRPdJwrx+Vpa+tNsGGA6zuKUYXr3twD3nOR/1emeN0SbJi Y4gsNXWxuiO8WT6EK1yWlB0Uc+qo03WXDB1xMzaj7Jhdwr74YVl19BVt0dpCl+0lzojy 2L+A== 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=yffGKK3pmh24JPHx2bCB/QJN3iGjGuoKDMn1gJXntZwZzjLumHnpmobs9prbivb3NS +pUxuqukQfY9RZSsjKCb9QDjJ1XsamuClLS895Zs0fAywtDswERh1LIfohb1q8Xyg/JQ 3rJdwbGXHm8H3RQCQxe6KlP0lvYOY3oGIloyGkHpzmqho1oIm7qiHvAW0GJ+cmuiYboG pI5TpRBcQk/ZsC2qfXokzlx75XaWqEJGixXZNyhNHF95Qgz/T6nMezUSkFJmoE1Ue4AZ he8cQIskiCKfNS3MJ+HlRR/+ZaeGjo2PQ/xIzfaT81b7Tr0H0kM8MkcdksKN0rDEqDMh 1jGQ== X-Gm-Message-State: AOAM530SnVbAeBldYLkNhDb7xAF6mhMiZC4uiWfWYAsSibS3aNbL0Fjv 5HuYhdqpH7/YOREgROKXRaI= X-Google-Smtp-Source: ABdhPJxu/+RIi87EI1f36Vr7Li+Ul/kNIIoagY73de2BeXztI3uQN8w4l7WqyA51zpnq1qGpZm55vg== X-Received: by 2002:a17:906:1c12:b0:6f3:9eed:e0 with SMTP id k18-20020a1709061c1200b006f39eed00e0mr14192987ejg.656.1651075654602; Wed, 27 Apr 2022 09:07:34 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:34 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 15/18] net: netcp: Remove usage of list iterator for list_add() after loop body Date: Wed, 27 Apr 2022 18:06:32 +0200 Message-Id: <20220427160635.420492-16-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.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 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; From patchwork Wed Apr 27 16:06:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623141 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=QdO1SZDa; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpP680D75z9s5V for ; Thu, 28 Apr 2022 02:17:19 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpP6751z5z3ds1 for ; Thu, 28 Apr 2022 02:17:19 +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=QdO1SZDa; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::62a; helo=mail-ej1-x62a.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=QdO1SZDa; dkim-atps=neutral Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (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 4KpNtz0sgbz3br1 for ; Thu, 28 Apr 2022 02:07:39 +1000 (AEST) Received: by mail-ej1-x62a.google.com with SMTP id i27so4346464ejd.9 for ; Wed, 27 Apr 2022 09:07:38 -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=vgJhsUA0t53G3i/our+ohO3psku9eyW28VU5QSKiZig=; b=QdO1SZDa4iev+atCa/l33RZOTYxU8Tm6OBJDuf3wFR1IPldpmE0Zz1hGsOF0mrH3tp Rrbgry+KLq2g5sBompEWvjwLxY/s/BnZGQGzzRqRqXLHBTYLUYGEpJu906ZngqiA10I2 p881qc+TsKdacaJize2/DNjc/WdmBcRP99WCcLj6IETGvqy23i2A6EI4klZ1jjJeda8b SmmzFz4xtkLCcGeLFvx7Lz4Frop8YYjZXS/gLlZqdgiJGfMo9V1SPUpzzANTuBoVYNJK IlRCbSielt0CFTgv7ZMUDxqDNtKQ026XVmFIuWJY91BdH+nbOdJPWD/XeYlhk3N5g+Nu q1UQ== 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=vgJhsUA0t53G3i/our+ohO3psku9eyW28VU5QSKiZig=; b=Rstj8WG10tm+g1ItOmuzNNi379m89P84AQT6/ctBXhPzPsNO8B+b9lKILxLz8d1xLX 6E/Yn2FQxpsAWrmt1sr7tSeDEmhZ/3vHfUETm6jtJZ+j/eGgaY33PC15WhExDIqGD0Pl +avNocdxB6tX8FZ3NapdvjuO7WRagjEajWjWp/+DwuQK04PxWTQryiQTae/JkhNxAcM/ 3qnZ4eaO0sbfCGFW41rBXpiugfvWb/cFijWOZjM2y7W3vh02O2reeQgwBiDTf66SOyf/ vNtBxDgwbK7YT7hhJ9b/itlHH3ZWg/v/Z33pcO0as140H4v95CpBXkajeadAaAn3bqX+ FQZQ== X-Gm-Message-State: AOAM533DB3yOfsjMJPUC+UjZG/f27B1Yugpj7D1nsHKhSR5tRe0R2CJ+ RnZ4KcRqtSX9SMkr+w9e9Qk= X-Google-Smtp-Source: ABdhPJxySUvwtY5DIqWX7IFtrekY9kkCubgf/t3517/f4PE7o1mxgYeQStUpKexVIlQ/w9B/1wLAJg== X-Received: by 2002:a17:907:7b8c:b0:6f3:a7d8:2609 with SMTP id ne12-20020a1709077b8c00b006f3a7d82609mr11153301ejc.53.1651075655941; Wed, 27 Apr 2022 09:07:35 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:35 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 16/18] ps3_gelic: Replace usage of found with dedicated list iterator variable Date: Wed, 27 Apr 2022 18:06:33 +0200 Message-Id: <20220427160635.420492-17-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 instead of a found boolean [1]. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- .../net/ethernet/toshiba/ps3_gelic_wireless.c | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c b/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c index dc14a66583ff..c8a016c902cd 100644 --- a/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c +++ b/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c @@ -1495,14 +1495,14 @@ static int gelic_wl_start_scan(struct gelic_wl_info *wl, int always_scan, */ static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl) { + struct gelic_wl_scan_info *target = NULL, *iter, *tmp; struct gelic_eurus_cmd *cmd = NULL; - struct gelic_wl_scan_info *target, *tmp; struct gelic_wl_scan_info *oldest = NULL; struct gelic_eurus_scan_info *scan_info; unsigned int scan_info_size; union iwreq_data data; unsigned long this_time = jiffies; - unsigned int data_len, i, found, r; + unsigned int data_len, i, r; void *buf; pr_debug("%s:start\n", __func__); @@ -1539,14 +1539,14 @@ static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl) wl->scan_stat = GELIC_WL_SCAN_STAT_GOT_LIST; /* mark all entries are old */ - list_for_each_entry_safe(target, tmp, &wl->network_list, list) { - target->valid = 0; + list_for_each_entry_safe(iter, tmp, &wl->network_list, list) { + iter->valid = 0; /* expire too old entries */ - if (time_before(target->last_scanned + wl->scan_age, + if (time_before(iter->last_scanned + wl->scan_age, this_time)) { - kfree(target->hwinfo); - target->hwinfo = NULL; - list_move_tail(&target->list, &wl->network_free_list); + kfree(iter->hwinfo); + iter->hwinfo = NULL; + list_move_tail(&iter->list, &wl->network_free_list); } } @@ -1569,22 +1569,22 @@ static void gelic_wl_scan_complete_event(struct gelic_wl_info *wl) continue; } - found = 0; + target = NULL; oldest = NULL; - list_for_each_entry(target, &wl->network_list, list) { - if (ether_addr_equal(&target->hwinfo->bssid[2], + list_for_each_entry(iter, &wl->network_list, list) { + if (ether_addr_equal(&iter->hwinfo->bssid[2], &scan_info->bssid[2])) { - found = 1; + target = iter; pr_debug("%s: same BBS found scanned list\n", __func__); break; } if (!oldest || - (target->last_scanned < oldest->last_scanned)) - oldest = target; + (iter->last_scanned < oldest->last_scanned)) + oldest = iter; } - if (!found) { + if (!target) { /* not found in the list */ if (list_empty(&wl->network_free_list)) { /* expire oldest */ From patchwork Wed Apr 27 16:06:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623147 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=j9VN3560; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpP6r5G6Xz9s5V for ; Thu, 28 Apr 2022 02:17:56 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpP6r43Sjz3dtF for ; Thu, 28 Apr 2022 02:17:56 +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=j9VN3560; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::62c; helo=mail-ej1-x62c.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=j9VN3560; dkim-atps=neutral Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) (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 4KpNv04Dksz3bpY for ; Thu, 28 Apr 2022 02:07:40 +1000 (AEST) Received: by mail-ej1-x62c.google.com with SMTP id i19so4330761eja.11 for ; Wed, 27 Apr 2022 09:07:40 -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=yEn2KXl6YaWL8lEsoeTa0NhbbIFQf0W1A7EAGx1tWC4=; b=j9VN3560QziYTFS6d7J5Qq58hDCrTHjdmjOyr5NqrbaJEKStDuM4vruZjymlSyiLMc Dh8INfUNhWcjaH37Z/xtK+hpI+Reivc925N29H3notA/4MG5STF7Y/S8UULAjLrvAk3x tQn1C8WCge5lQNlQTq2kdY8XDgx8f0A9p9ySxSQKzu7jp7FN1JqTunv95UrEld8tjPJ6 VRtqjtn30d1MvYY4uxLZ1e/4kHIF/t7sayeN4qAuNESeiGnOPggh5aeNzHUApnNASKpY U2rFXGyJBscsO38UWjuCkyg5A6HAurFoW4JUoqmcrmYZbpbtGpqoy5En4hTB6XKRCff/ jCgA== 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=yEn2KXl6YaWL8lEsoeTa0NhbbIFQf0W1A7EAGx1tWC4=; b=1hsmRq79EX3WapXSSbWjFQBAvSGanw/8jwUchZxoRp9hk1/emC/cYgqckA52bW4gqt KfDuUO8zc8+6Lrq9legJVRCpu2QXoA1mQkURvXTFWNjxL8lB+MwTgASWylDsFtv79yq/ SRFtCTEOjPiZ/pkRKM8+CK7bMrquriw3AWVJJDCaEt4seL09DX0VyQvxZ/4HA/XAk/Ha k8/KLiTxMiUjKZ1pv0hri0EHiHkmwkIbsGdPDlrvrH3nVHehJIjCIU+S+ww8+VM36oyG glBl+y4hcefvK12Zvayr0uku9/CGI4vdO/K7Rjm6++b4aYQrw0v51DenJKOOyD1QU9PR PEzg== X-Gm-Message-State: AOAM533vPQl/JkmIcWtaeNsk3v5tYv1Y9pEjtOv0dgRISiM/SKGYZK/r bEuU+jRRfCqGL9KxXMz95lE= X-Google-Smtp-Source: ABdhPJyMZ+IgV1RXVOMRtwqWm4DRsNx2pj45I590H75mGqMsBCpfqP0l0qRvqSkNr3e05xJ3Sk+wew== X-Received: by 2002:a17:907:eab:b0:6dd:e8fe:3dc with SMTP id ho43-20020a1709070eab00b006dde8fe03dcmr26843254ejc.165.1651075657398; Wed, 27 Apr 2022 09:07:37 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:37 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 17/18] ipvlan: Remove usage of list iterator variable for the loop body Date: Wed, 27 Apr 2022 18:06:34 +0200 Message-Id: <20220427160635.420492-18-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" In preparation to limit the scope of the list iterator variable to the list traversal loop, use a dedicated pointer to iterate through the list [1]. Since that variable should not be used past the loop iteration, a separate variable is used to 'remember the current location within the loop'. To either continue iterating from that position or start a new iteration (if the previous iteration was complete) list_prepare_entry() is used. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- drivers/net/ipvlan/ipvlan_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index 696e245f6d00..063d7c30e944 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -9,7 +9,7 @@ static int ipvlan_set_port_mode(struct ipvl_port *port, u16 nval, struct netlink_ext_ack *extack) { - struct ipvl_dev *ipvlan; + struct ipvl_dev *ipvlan, *tmp = NULL; unsigned int flags; int err; @@ -26,8 +26,10 @@ static int ipvlan_set_port_mode(struct ipvl_port *port, u16 nval, flags & ~IFF_NOARP, extack); } - if (unlikely(err)) + if (unlikely(err)) { + tmp = ipvlan; goto fail; + } } if (nval == IPVLAN_MODE_L3S) { /* New mode is L3S */ @@ -43,6 +45,7 @@ static int ipvlan_set_port_mode(struct ipvl_port *port, u16 nval, return 0; fail: + ipvlan = list_prepare_entry(tmp, &port->ipvlans, pnode); /* Undo the flags changes that have been done so far. */ list_for_each_entry_continue_reverse(ipvlan, &port->ipvlans, pnode) { flags = ipvlan->dev->flags; From patchwork Wed Apr 27 16:06:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 1623148 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=djNzVmRe; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KpP7X5rvqz9s5V for ; Thu, 28 Apr 2022 02:18:32 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KpP7X3bCvz3fMC for ; Thu, 28 Apr 2022 02:18:32 +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=djNzVmRe; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::631; helo=mail-ej1-x631.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=djNzVmRe; dkim-atps=neutral Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) (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 4KpNv20LnRz3bs8 for ; Thu, 28 Apr 2022 02:07:42 +1000 (AEST) Received: by mail-ej1-x631.google.com with SMTP id l18so4354738ejc.7 for ; Wed, 27 Apr 2022 09:07:41 -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=/A0b7QXPnRxcdjzjvBy95srF3RhPajcOL797uVjW17k=; b=djNzVmRevWSY+hIiC1/H30PkHbSU6xqUomoS6vNxNxSsA2vgIsDJmjFdrGiJt1K8MS XvJVUBQenTNDmnRY1OxwRpXMU6eq8+3j9NKMg8A0/fSUm/OXLuHTuvFMOxq1tfiv5/lo PETw/pty71e5r7Z5xql/U9OyQrFDpphWq0AKn82ZX5A9j9EvNXqncx1kGerazGaEhlhW BtwUHrzoVQidChJdfESgX4ChoMs1jqCIz+LCsesKzeGmJ4AwqLUMeAhlcZ0ui7hA1ca6 FYrGCeBuXiEVcQ+uN5Ej2ozdZDqA9mtVVLC0RLXFL7lInO3enpCUsINJFZgSSzcJVwCF jf8Q== 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=/A0b7QXPnRxcdjzjvBy95srF3RhPajcOL797uVjW17k=; b=B2T/IwcpRnjhU3MfW68juZiTehpJWflqFYehxp2SskRl/wMiVXfK1ikb5i6F1TjZEA mEmXD1Otc+X6qwt3M5TuhK2FKCL4S5h0DjCpfABsXwil2UHDsZ1cbAmeae3TQu5bP4iS avp90NsohFyBnhu/e6EcedboBVhy/c0Y8KZH/JoTpw/IsKJrfQ+F+MWF04Fh3kDRsCCT 7Dt+fXGLUfbQZQ5uSgoGAnZUjH6G1uTD1TcNFvRFu4GemIBjiHQHzu1HQRjjlxnijzBn ycxB4thuWLqKA4GAFK+TZLqGwqi/1oGvJ3YKZ4pqugKIiw7d14oxHuBEepc10GCj8mLW oCkg== X-Gm-Message-State: AOAM531XSuc51Wn2RBoFUfAna7Rs0Wam3njLRY6xaHvffMUnUCHhWFDr Lxw3W55cy/O9SHdOrd6w4/g= X-Google-Smtp-Source: ABdhPJzZ9GK5JMKIlGUFt2skqXUpBcMIDshg75p8eWcFCf8XLqwMsnXkioKQLmTu+ChB5hH1wuiIcQ== X-Received: by 2002:a17:907:98eb:b0:6f3:ce56:c1a2 with SMTP id ke11-20020a17090798eb00b006f3ce56c1a2mr2984393ejc.173.1651075659037; Wed, 27 Apr 2022 09:07:39 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:38 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Subject: [PATCH net-next v5 18/18] team: Remove use of list iterator variable for list_for_each_entry_from() Date: Wed, 27 Apr 2022 18:06:35 +0200 Message-Id: <20220427160635.420492-19-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160635.420492-1-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 , Song Liu , Alexei Starovoitov , Eric Dumazet , Paul Mackerras , Ariel Elior , Florian Fainelli , Daniel Borkmann , Steen Hegelund , John Fastabend , Andrii Nakryiko , "Bos, H.J." , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, Martin Habets , Paolo Abeni , Vivien Didelot , Jiri Pirko , Arnd Bergmann , KP Singh , Christophe JAILLET , Jakob Koschel , Jakub Kicinski , Brian Johannesmeyer , Lars Povlsen , Colin Ian King , Manish Chopra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, UNGLinuxDriver@microchip.com, Yonghong Song , Edward Cree , Casper Andersson , Xu Wang , Cristiano Giuffrida , bpf@vger.kernel.org, Vladimir Oltean , linuxppc-dev@lists.ozlabs.org, Martin KaFai Lau , Mike Rapoport Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" In preparation to limit the scope of the list iterator variable to the list traversal loop, use a dedicated pointer to iterate through the list [1]. Since that variable should not be used past the loop iteration, a separate variable is used to 'remember the current location within the loop'. To either continue iterating from that position or skip the iteration (if the previous iteration was complete) list_prepare_entry() is used. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- drivers/net/team/team.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c index b07dde6f0abf..688c4393f099 100644 --- a/drivers/net/team/team.c +++ b/drivers/net/team/team.c @@ -2425,17 +2425,17 @@ static int team_nl_send_options_get(struct team *team, u32 portid, u32 seq, int flags, team_nl_send_func_t *send_func, struct list_head *sel_opt_inst_list) { + struct team_option_inst *opt_inst, *tmp = NULL; struct nlattr *option_list; struct nlmsghdr *nlh; void *hdr; - struct team_option_inst *opt_inst; int err; struct sk_buff *skb = NULL; bool incomplete; int i; - opt_inst = list_first_entry(sel_opt_inst_list, - struct team_option_inst, tmp_list); + tmp = list_first_entry(sel_opt_inst_list, + struct team_option_inst, tmp_list); start_again: err = __send_and_alloc_skb(&skb, team, portid, send_func); @@ -2456,7 +2456,9 @@ static int team_nl_send_options_get(struct team *team, u32 portid, u32 seq, goto nla_put_failure; i = 0; + opt_inst = list_prepare_entry(tmp, sel_opt_inst_list, tmp_list); incomplete = false; + tmp = NULL; list_for_each_entry_from(opt_inst, sel_opt_inst_list, tmp_list) { err = team_nl_fill_one_option_get(skb, team, opt_inst); if (err) { @@ -2464,6 +2466,7 @@ static int team_nl_send_options_get(struct team *team, u32 portid, u32 seq, if (!i) goto errout; incomplete = true; + tmp = opt_inst; break; } goto errout; @@ -2707,14 +2710,14 @@ static int team_nl_send_port_list_get(struct team *team, u32 portid, u32 seq, struct nlattr *port_list; struct nlmsghdr *nlh; void *hdr; - struct team_port *port; + struct team_port *port, *tmp = NULL; int err; struct sk_buff *skb = NULL; bool incomplete; int i; - port = list_first_entry_or_null(&team->port_list, - struct team_port, list); + tmp = list_first_entry_or_null(&team->port_list, + struct team_port, list); start_again: err = __send_and_alloc_skb(&skb, team, portid, send_func); @@ -2744,7 +2747,9 @@ static int team_nl_send_port_list_get(struct team *team, u32 portid, u32 seq, err = team_nl_fill_one_port_get(skb, one_port); if (err) goto errout; - } else if (port) { + } else { + port = list_prepare_entry(tmp, &team->port_list, list); + tmp = NULL; list_for_each_entry_from(port, &team->port_list, list) { err = team_nl_fill_one_port_get(skb, port); if (err) { @@ -2752,6 +2757,7 @@ static int team_nl_send_port_list_get(struct team *team, u32 portid, u32 seq, if (!i) goto errout; incomplete = true; + tmp = port; break; } goto errout;