diff mbox series

sctp: replace usage of found with dedicated list iterator variable

Message ID 20220324072257.62674-1-jakobkoschel@gmail.com (mailing list archive)
State Deferred
Delegated to: Netdev Maintainers
Headers show
Series sctp: replace usage of found with dedicated list iterator variable | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 31 this patch: 31
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 21 this patch: 21
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 34 this patch: 34
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jakob Koschel March 24, 2022, 7:22 a.m. UTC
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(-)


base-commit: f443e374ae131c168a065ea1748feac6b2e76613

Comments

Marcelo Ricardo Leitner March 25, 2022, 8:57 p.m. UTC | #1
On Thu, Mar 24, 2022 at 08:22:57AM +0100, Jakob Koschel wrote:
> 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>

Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
diff mbox series

Patch

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;
 	}