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>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
04948a3469
commit
2568dd1b6b
@@ -348,36 +348,33 @@ static int listen_all_addrinfo(struct addrinfo *ai_head, int sockfdlist[])
|
|||||||
int ret, nsockfd = 0;
|
int ret, nsockfd = 0;
|
||||||
|
|
||||||
for (ai = ai_head; ai && nsockfd < MAXSOCKFD; ai = ai->ai_next) {
|
for (ai = ai_head; ai && nsockfd < MAXSOCKFD; ai = ai->ai_next) {
|
||||||
sockfdlist[nsockfd] = socket(ai->ai_family, ai->ai_socktype,
|
int sock = socket(ai->ai_family, ai->ai_socktype,
|
||||||
ai->ai_protocol);
|
ai->ai_protocol);
|
||||||
if (sockfdlist[nsockfd] < 0)
|
if (sock < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
usbip_net_set_reuseaddr(sockfdlist[nsockfd]);
|
usbip_net_set_reuseaddr(sock);
|
||||||
usbip_net_set_nodelay(sockfdlist[nsockfd]);
|
usbip_net_set_nodelay(sock);
|
||||||
|
|
||||||
if (sockfdlist[nsockfd] >= FD_SETSIZE) {
|
if (sock >= FD_SETSIZE) {
|
||||||
close(sockfdlist[nsockfd]);
|
close(sock);
|
||||||
sockfdlist[nsockfd] = -1;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = bind(sockfdlist[nsockfd], ai->ai_addr, ai->ai_addrlen);
|
ret = bind(sock, ai->ai_addr, ai->ai_addrlen);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
close(sockfdlist[nsockfd]);
|
close(sock);
|
||||||
sockfdlist[nsockfd] = -1;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = listen(sockfdlist[nsockfd], SOMAXCONN);
|
ret = listen(sock, SOMAXCONN);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
close(sockfdlist[nsockfd]);
|
close(sock);
|
||||||
sockfdlist[nsockfd] = -1;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_addrinfo(ai);
|
log_addrinfo(ai);
|
||||||
nsockfd++;
|
sockfdlist[nsockfd++] = sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsockfd == 0)
|
if (nsockfd == 0)
|
||||||
|
Reference in New Issue
Block a user