diff options
author | Anthony Foiani <anthony.foiani@gmail.com> | 2013-07-08 06:52:41 (GMT) |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-07-23 22:04:19 (GMT) |
commit | 2568dd1b6b800dd0fdff5aa997cf7d0c46c19ffe (patch) | |
tree | cc70df3a3dcc9d181b450ae20874ab8a4a5f911e | |
parent | 04948a34698ddfa8823148b3a357cf3438e1433b (diff) | |
download | linux-fsl-qoriq-2568dd1b6b800dd0fdff5aa997cf7d0c46c19ffe.tar.xz |
staging: usbip: use local variable while setting up socket
Using a simple integer makes the code easier to read and removes the
need to blank out array elements in case of errors.
Signed-Off-By: Anthony Foiani <anthony.foiani@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/usbip/userspace/src/usbipd.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/drivers/staging/usbip/userspace/src/usbipd.c b/drivers/staging/usbip/userspace/src/usbipd.c index 9d38241..d833e7b 100644 --- a/drivers/staging/usbip/userspace/src/usbipd.c +++ b/drivers/staging/usbip/userspace/src/usbipd.c @@ -348,36 +348,33 @@ static int listen_all_addrinfo(struct addrinfo *ai_head, int sockfdlist[]) int ret, nsockfd = 0; for (ai = ai_head; ai && nsockfd < MAXSOCKFD; ai = ai->ai_next) { - sockfdlist[nsockfd] = socket(ai->ai_family, ai->ai_socktype, - ai->ai_protocol); - if (sockfdlist[nsockfd] < 0) + int sock = socket(ai->ai_family, ai->ai_socktype, + ai->ai_protocol); + if (sock < 0) continue; - usbip_net_set_reuseaddr(sockfdlist[nsockfd]); - usbip_net_set_nodelay(sockfdlist[nsockfd]); + usbip_net_set_reuseaddr(sock); + usbip_net_set_nodelay(sock); - if (sockfdlist[nsockfd] >= FD_SETSIZE) { - close(sockfdlist[nsockfd]); - sockfdlist[nsockfd] = -1; + if (sock >= FD_SETSIZE) { + close(sock); continue; } - ret = bind(sockfdlist[nsockfd], ai->ai_addr, ai->ai_addrlen); + ret = bind(sock, ai->ai_addr, ai->ai_addrlen); if (ret < 0) { - close(sockfdlist[nsockfd]); - sockfdlist[nsockfd] = -1; + close(sock); continue; } - ret = listen(sockfdlist[nsockfd], SOMAXCONN); + ret = listen(sock, SOMAXCONN); if (ret < 0) { - close(sockfdlist[nsockfd]); - sockfdlist[nsockfd] = -1; + close(sock); continue; } log_addrinfo(ai); - nsockfd++; + sockfdlist[nsockfd++] = sock; } if (nsockfd == 0) |