Linux-SCTP Archive mirror
 help / color / mirror / Atom feed
From: Jakob Koschel <jakobkoschel@gmail.com>
To: Vlad Yasevich <vyasevich@gmail.com>
Cc: Neil Horman <nhorman@tuxdriver.com>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	linux-sctp@vger.kernel.org, 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] sctp: replace usage of found with dedicated list iterator variable
Date: Thu, 24 Mar 2022 08:22:57 +0100	[thread overview]
Message-ID: <20220324072257.62674-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/sctp/bind_addr.c | 15 +++++++--------
 net/sctp/ipv6.c      | 24 +++++++++++-------------
 net/sctp/protocol.c  | 24 +++++++++++-------------
 3 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
index 59e653b528b1..c85ade7863bf 100644
--- a/net/sctp/bind_addr.c
+++ b/net/sctp/bind_addr.c
@@ -172,23 +172,22 @@ int sctp_add_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *new,
  */
 int sctp_del_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *del_addr)
 {
-	struct sctp_sockaddr_entry *addr, *temp;
-	int found = 0;
+	struct sctp_sockaddr_entry *addr = NULL, *iter, *temp;
 
 	/* We hold the socket lock when calling this function,
 	 * and that acts as a writer synchronizing lock.
 	 */
-	list_for_each_entry_safe(addr, temp, &bp->address_list, list) {
-		if (sctp_cmp_addr_exact(&addr->a, del_addr)) {
+	list_for_each_entry_safe(iter, temp, &bp->address_list, list) {
+		if (sctp_cmp_addr_exact(&iter->a, del_addr)) {
 			/* Found the exact match. */
-			found = 1;
-			addr->valid = 0;
-			list_del_rcu(&addr->list);
+			addr = iter;
+			iter->valid = 0;
+			list_del_rcu(&iter->list);
 			break;
 		}
 	}
 
-	if (found) {
+	if (addr) {
 		kfree_rcu(addr, rcu);
 		SCTP_DBG_OBJCNT_DEC(addr);
 		return 0;
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 470dbdc27d58..803950277f56 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -76,10 +76,8 @@ static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev,
 				void *ptr)
 {
 	struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
-	struct sctp_sockaddr_entry *addr = NULL;
-	struct sctp_sockaddr_entry *temp;
+	struct sctp_sockaddr_entry *addr = NULL, *iter, *temp;
 	struct net *net = dev_net(ifa->idev->dev);
-	int found = 0;
 
 	switch (ev) {
 	case NETDEV_UP:
@@ -97,21 +95,21 @@ static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev,
 		break;
 	case NETDEV_DOWN:
 		spin_lock_bh(&net->sctp.local_addr_lock);
-		list_for_each_entry_safe(addr, temp,
-					&net->sctp.local_addr_list, list) {
-			if (addr->a.sa.sa_family == AF_INET6 &&
-			    ipv6_addr_equal(&addr->a.v6.sin6_addr,
+		list_for_each_entry_safe(iter, temp,
+					 &net->sctp.local_addr_list, list) {
+			if (iter->a.sa.sa_family == AF_INET6 &&
+			    ipv6_addr_equal(&iter->a.v6.sin6_addr,
 					    &ifa->addr) &&
-			    addr->a.v6.sin6_scope_id == ifa->idev->dev->ifindex) {
-				sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
-				found = 1;
-				addr->valid = 0;
-				list_del_rcu(&addr->list);
+			    iter->a.v6.sin6_scope_id == ifa->idev->dev->ifindex) {
+				sctp_addr_wq_mgmt(net, iter, SCTP_ADDR_DEL);
+				addr = iter;
+				iter->valid = 0;
+				list_del_rcu(&iter->list);
 				break;
 			}
 		}
 		spin_unlock_bh(&net->sctp.local_addr_lock);
-		if (found)
+		if (addr)
 			kfree_rcu(addr, rcu);
 		break;
 	}
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 35928fefae33..6f1d7fd83465 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -777,10 +777,8 @@ static int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev,
 			       void *ptr)
 {
 	struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
-	struct sctp_sockaddr_entry *addr = NULL;
-	struct sctp_sockaddr_entry *temp;
+	struct sctp_sockaddr_entry *addr = NULL, *iter, *temp;
 	struct net *net = dev_net(ifa->ifa_dev->dev);
-	int found = 0;
 
 	switch (ev) {
 	case NETDEV_UP:
@@ -797,20 +795,20 @@ static int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev,
 		break;
 	case NETDEV_DOWN:
 		spin_lock_bh(&net->sctp.local_addr_lock);
-		list_for_each_entry_safe(addr, temp,
-					&net->sctp.local_addr_list, list) {
-			if (addr->a.sa.sa_family == AF_INET &&
-					addr->a.v4.sin_addr.s_addr ==
-					ifa->ifa_local) {
-				sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
-				found = 1;
-				addr->valid = 0;
-				list_del_rcu(&addr->list);
+		list_for_each_entry_safe(iter, temp,
+					 &net->sctp.local_addr_list, list) {
+			if (iter->a.sa.sa_family == AF_INET &&
+			    iter->a.v4.sin_addr.s_addr ==
+			    ifa->ifa_local) {
+				sctp_addr_wq_mgmt(net, iter, SCTP_ADDR_DEL);
+				addr = iter;
+				iter->valid = 0;
+				list_del_rcu(&iter->list);
 				break;
 			}
 		}
 		spin_unlock_bh(&net->sctp.local_addr_lock);
-		if (found)
+		if (addr)
 			kfree_rcu(addr, rcu);
 		break;
 	}

base-commit: f443e374ae131c168a065ea1748feac6b2e76613
-- 
2.25.1


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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24  7:22 Jakob Koschel [this message]
2022-03-25 20:57 ` [PATCH] sctp: replace usage of found with dedicated list iterator variable Marcelo Ricardo Leitner

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=20220324072257.62674-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=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sctp@vger.kernel.org \
    --cc=marcelo.leitner@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=pabeni@redhat.com \
    --cc=rppt@kernel.org \
    --cc=vyasevich@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 read-only IMAP folder(s) and NNTP newsgroup(s).