netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] taprio: replace usage of found with dedicated list iterator variable
@ 2022-03-24  7:26 Jakob Koschel
  2022-03-30 23:15 ` Vinicius Costa Gomes
  0 siblings, 1 reply; 6+ messages in thread
From: Jakob Koschel @ 2022-03-24  7:26 UTC (permalink / raw)
  To: Vinicius Costa Gomes
  Cc: Jamal Hadi Salim, Cong Wang, Jiri Pirko, David S. Miller,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, Mike Rapoport,
	Brian Johannesmeyer, Cristiano Giuffrida, Bos, H.J.,
	Jakob Koschel

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-04  3:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  7:26 [PATCH] taprio: replace usage of found with dedicated list iterator variable Jakob Koschel
2022-03-30 23:15 ` 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

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).