netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakob Koschel <jakobkoschel@gmail.com>
To: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Jiri Pirko <jiri@resnulli.us>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mike Rapoport <rppt@kernel.org>,
	"Brian Johannesmeyer" <bjohannesmeyer@gmail.com>,
	Cristiano Giuffrida <c.giuffrida@vu.nl>,
	"Bos, H.J." <h.j.bos@vu.nl>,
	Jakob Koschel <jakobkoschel@gmail.com>
Subject: [PATCH] taprio: replace usage of found with dedicated list iterator variable
Date: Thu, 24 Mar 2022 08:26:07 +0100	[thread overview]
Message-ID: <20220324072607.63594-1-jakobkoschel@gmail.com> (raw)

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/
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
 net/sched/sch_cbs.c    | 11 +++++------
 net/sched/sch_taprio.c | 11 +++++------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/net/sched/sch_cbs.c b/net/sched/sch_cbs.c
index 459cc240eda9..4ea93a5d46cf 100644
--- a/net/sched/sch_cbs.c
+++ b/net/sched/sch_cbs.c
@@ -333,9 +333,8 @@ static int cbs_dev_notifier(struct notifier_block *nb, unsigned long event,
 			    void *ptr)
 {
 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
-	struct cbs_sched_data *q;
+	struct cbs_sched_data *q = NULL, *iter;
 	struct net_device *qdev;
-	bool found = false;
 
 	ASSERT_RTNL();
 
@@ -343,16 +342,16 @@ static int cbs_dev_notifier(struct notifier_block *nb, unsigned long event,
 		return NOTIFY_DONE;
 
 	spin_lock(&cbs_list_lock);
-	list_for_each_entry(q, &cbs_list, cbs_list) {
-		qdev = qdisc_dev(q->qdisc);
+	list_for_each_entry(iter, &cbs_list, cbs_list) {
+		qdev = qdisc_dev(iter->qdisc);
 		if (qdev == dev) {
-			found = true;
+			q = iter;
 			break;
 		}
 	}
 	spin_unlock(&cbs_list_lock);
 
-	if (found)
+	if (q)
 		cbs_set_port_rate(dev, q);
 
 	return NOTIFY_DONE;
diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index 377f896bdedc..9403ae4bf107 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -1096,9 +1096,8 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event,
 			       void *ptr)
 {
 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
+	struct taprio_sched *q = NULL, *iter;
 	struct net_device *qdev;
-	struct taprio_sched *q;
-	bool found = false;
 
 	ASSERT_RTNL();
 
@@ -1106,16 +1105,16 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event,
 		return NOTIFY_DONE;
 
 	spin_lock(&taprio_list_lock);
-	list_for_each_entry(q, &taprio_list, taprio_list) {
-		qdev = qdisc_dev(q->root);
+	list_for_each_entry(iter, &taprio_list, taprio_list) {
+		qdev = qdisc_dev(iter->root);
 		if (qdev == dev) {
-			found = true;
+			q = iter;
 			break;
 		}
 	}
 	spin_unlock(&taprio_list_lock);
 
-	if (found)
+	if (q)
 		taprio_set_picos_per_byte(dev, q);
 
 	return NOTIFY_DONE;

base-commit: f443e374ae131c168a065ea1748feac6b2e76613
-- 
2.25.1


             reply	other threads:[~2022-03-24  7:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24  7:26 Jakob Koschel [this message]
2022-03-30 23:15 ` [PATCH] taprio: replace usage of found with dedicated list iterator variable Vinicius Costa Gomes
2022-03-31  9:26   ` Jakob Koschel
2022-03-31 17:58     ` Vinicius Costa Gomes
2022-04-03 11:53       ` Jakob Koschel
2022-04-04  3:55         ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220324072607.63594-1-jakobkoschel@gmail.com \
    --to=jakobkoschel@gmail.com \
    --cc=bjohannesmeyer@gmail.com \
    --cc=c.giuffrida@vu.nl \
    --cc=davem@davemloft.net \
    --cc=h.j.bos@vu.nl \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rppt@kernel.org \
    --cc=vinicius.gomes@intel.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).