linux-um.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] um: Use common error handling code in port_listen_fd()
@ 2017-10-20 17:29 SF Markus Elfring
  2017-10-20 18:06 ` Joe Perches
  2017-10-23  8:48 ` [PATCH] " Dan Carpenter
  0 siblings, 2 replies; 9+ messages in thread
From: SF Markus Elfring @ 2017-10-20 17:29 UTC (permalink / raw)
  To: user-mode-linux-devel, Jeff Dike, Richard Weinberger
  Cc: user-mode-linux-user, kernel-janitors, LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 20 Oct 2017 19:24:39 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/um/drivers/port_user.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/arch/um/drivers/port_user.c b/arch/um/drivers/port_user.c
index 9a8e1b64c22e..8d95fa5641af 100644
--- a/arch/um/drivers/port_user.c
+++ b/arch/um/drivers/port_user.c
@@ -118,29 +118,24 @@ int port_listen_fd(int port)
 		return -errno;
 
 	arg = 1;
-	if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &arg, sizeof(arg)) < 0) {
-		err = -errno;
-		goto out;
-	}
+	if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &arg, sizeof(arg)) < 0)
+		goto failure_indication;
 
 	addr.sin_family = AF_INET;
 	addr.sin_port = htons(port);
 	addr.sin_addr.s_addr = htonl(INADDR_ANY);
-	if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-		err = -errno;
-		goto out;
-	}
-
-	if (listen(fd, 1) < 0) {
-		err = -errno;
-		goto out;
-	}
+	if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0 ||
+	    listen(fd, 1) < 0)
+		goto failure_indication;
 
 	err = os_set_fd_block(fd, 0);
 	if (err < 0)
 		goto out;
 
 	return fd;
+
+ failure_indication:
+	err = -errno;
  out:
 	close(fd);
 	return err;
-- 
2.14.2



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

end of thread, other threads:[~2017-10-23 12:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-20 17:29 [PATCH] um: Use common error handling code in port_listen_fd() SF Markus Elfring
2017-10-20 18:06 ` Joe Perches
2017-10-20 18:22   ` SF Markus Elfring
2017-10-23  8:48 ` [PATCH] " Dan Carpenter
2017-10-23  9:01   ` SF Markus Elfring
2017-10-23  9:10     ` Dan Carpenter
2017-10-23  9:17       ` SF Markus Elfring
2017-10-23 10:28   ` [PATCH] " Markus Trippelsdorf
2017-10-23 12:04     ` SF Markus Elfring

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