Skip to contentSkip to conversation

replace if .. goto with while

PATCH In review Horms 2 participants 3 messages Dec 18, 2006 – Jan 3, 2007

Subsystems (2)
lore
Share & tools
lore

Horms

author
#0 lore raw

PATCH 1/1 replace if .. goto with while

I guess that this code used to be more complex, but replacing the goto with a while seems to make things a bit more readable. Or in other words, two fairly gratuitous goto are removed.

On a related note, I wonder if there should be a limit to how many times it tries.

net/ipv4/ipvs/ip_vs_sync.c +2 -6
Index: linux-2.6/net/ipv4/ipvs/ip_vs_sync.c
===================================================================
@@ -822,12 +822,10 @@
 
 	/* fork the sync thread here, then the parent process of the
 	   sync thread is the init process after this thread exits. */
-  repeat:
-	if ((pid = kernel_thread(sync_thread, startup, 0)) < 0) {
+	while ((pid = kernel_thread(sync_thread, startup, 0)) < 0) {
 		IP_VS_ERR("could not create sync_thread due to %d... "
 			  "retrying.\n", pid);
 		msleep_interruptible(1000);
-		goto repeat;
 	}
 
 	return 0;
@@ -856,12 +854,10 @@
 		ip_vs_backup_syncid = syncid;
 	}
 
-  repeat:
-	if ((pid = kernel_thread(fork_sync_thread, &startup, 0)) < 0) {
+	while ((pid = kernel_thread(fork_sync_thread, &startup, 0)) < 0) {
 		IP_VS_ERR("could not create fork_sync_thread due to %d... "
 			  "retrying.\n", pid);
 		msleep_interruptible(1000);
-		goto repeat;
 	}
 
 	wait_for_completion(&startup);
maintainer
#1 lore raw

From: Horms <[email protected]>
Date: Mon, 18 Dec 2006 12:11:11 +0900

Quoted 8 lines

I guess that this code used to be more complex, but replacing the goto with a while seems to make things a bit more readable. Or in other words, two fairly gratuitous goto are removed.

On a related note, I wonder if there should be a limit to how many times it tries.

Yes, there should be, something like a limit of one. :-)

There is no reason to loop on something like this, just return a failure immediately if creating the kernel thread fails.

As a side note, if it's easy you might want to convert this over the the include/linux/kthread.h interfaces. I just did this for pktgen tonight and it cleaned a lot of stuff up.

author
#2 lore raw
Quoted 10 lines · David Miller

From: Horms <[email protected]>
Date: Mon, 18 Dec 2006 12:11:11 +0900

Quoted 7 lines

I guess that this code used to be more complex, but replacing the goto with a while seems to make things a bit more readable. Or in other words, two fairly gratuitous goto are removed.

On a related note, I wonder if there should be a limit to how many times it tries.

Quoted 7 lines
Quoted 1 line

Yes, there should be, something like a limit of one. :-)

There is no reason to loop on something like this, just return a failure immediately if creating the kernel thread fails.

Will do.

Quoted 3 lines

As a side note, if it's easy you might want to convert this over the the include/linux/kthread.h interfaces. I just did this for pktgen tonight and it cleaned a lot of stuff up.

Thanks, I will look into it.

Signature · 3 lines
Horms
  H: http://www.vergenet.net/~horms/
  W: http://www.valinux.co.jp/en/