* [patch 10/13] net/socket.c::sys_bind() cleanup.
@ 2004-11-22 6:43 akpm
2004-11-24 8:27 ` David S. Miller
0 siblings, 1 reply; 5+ messages in thread
From: akpm @ 2004-11-22 6:43 UTC (permalink / raw)
To: davem; +Cc: jgarzik, netdev, akpm, lcapitulino
From: "Luiz Fernando N. Capitulino" <lcapitulino@conectiva.com.br>
net/socket.c::sys_bind() is a bit complex function, the patch below makes
it more clear.
Signed-off-by: Luiz Capitulino <lcapitulino@conectiva.com.br>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---
25-akpm/net/socket.c | 29 +++++++++++++++++------------
1 files changed, 17 insertions(+), 12 deletions(-)
diff -puN net/socket.c~net-socketcsys_bind-cleanup net/socket.c
--- 25/net/socket.c~net-socketcsys_bind-cleanup 2004-11-21 22:42:53.618530984 -0800
+++ 25-akpm/net/socket.c 2004-11-21 22:43:00.586471696 -0800
@@ -1286,18 +1286,23 @@ asmlinkage long sys_bind(int fd, struct
char address[MAX_SOCK_ADDR];
int err;
- if((sock = sockfd_lookup(fd,&err))!=NULL)
- {
- if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) {
- err = security_socket_bind(sock, (struct sockaddr *)address, addrlen);
- if (err) {
- sockfd_put(sock);
- return err;
- }
- err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
- }
- sockfd_put(sock);
- }
+ sock = sockfd_lookup(fd, &err);
+ if (!sock)
+ goto out;
+
+ err = move_addr_to_kernel(umyaddr, addrlen, address);
+ if (err)
+ goto out_put;
+
+ err = security_socket_bind(sock, (struct sockaddr *)address, addrlen);
+ if (err)
+ goto out_put;
+
+ err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
+
+ out_put:
+ sockfd_put(sock);
+ out:
return err;
}
_
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch 10/13] net/socket.c::sys_bind() cleanup.
2004-11-22 6:43 [patch 10/13] net/socket.c::sys_bind() cleanup akpm
@ 2004-11-24 8:27 ` David S. Miller
2004-11-24 10:55 ` Luiz Fernando Capitulino
0 siblings, 1 reply; 5+ messages in thread
From: David S. Miller @ 2004-11-24 8:27 UTC (permalink / raw)
To: akpm; +Cc: jgarzik, netdev, akpm, lcapitulino
On Sun, 21 Nov 2004 22:43:56 -0800
akpm@osdl.org wrote:
> From: "Luiz Fernando N. Capitulino" <lcapitulino@conectiva.com.br>
>
> net/socket.c::sys_bind() is a bit complex function, the patch below makes
> it more clear.
>
> Signed-off-by: Luiz Capitulino <lcapitulino@conectiva.com.br>
> Signed-off-by: Andrew Morton <akpm@osdl.org>
This was commented on to be buggy, or at least change behavior.
The "if (err >= 0)" tests were changed to flat "if (err)" tests.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch 10/13] net/socket.c::sys_bind() cleanup.
2004-11-24 8:27 ` David S. Miller
@ 2004-11-24 10:55 ` Luiz Fernando Capitulino
2004-11-24 22:03 ` David Stevens
0 siblings, 1 reply; 5+ messages in thread
From: Luiz Fernando Capitulino @ 2004-11-24 10:55 UTC (permalink / raw)
To: David S. Miller; +Cc: akpm, jgarzik, netdev
David S. Miller wrote:
> On Sun, 21 Nov 2004 22:43:56 -0800
> akpm@osdl.org wrote:
>
>
>>From: "Luiz Fernando N. Capitulino" <lcapitulino@conectiva.com.br>
>>
>>net/socket.c::sys_bind() is a bit complex function, the patch below makes
>>it more clear.
>>
>>Signed-off-by: Luiz Capitulino <lcapitulino@conectiva.com.br>
>>Signed-off-by: Andrew Morton <akpm@osdl.org>
>
>
> This was commented on to be buggy, or at least change behavior.
> The "if (err >= 0)" tests were changed to flat "if (err)" tests.
It doesn't a buggy or change behaivor.
What happens here is that move_addr_to_kernel() returns 0
success and -EINVAL or -EFAULT on error. Thus, change from
"if (err >= 0)" to "if (err)" is safe.
Also, it was discussed and ACK'ed by James Morris:
http://lkml.org/lkml/2004/11/16/339
The real problem here I've made a bad patch
description. I'll try to make it better next time.
thanks,
--
Luiz Fernando N. Capitulino
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch 10/13] net/socket.c::sys_bind() cleanup.
2004-11-24 10:55 ` Luiz Fernando Capitulino
@ 2004-11-24 22:03 ` David Stevens
2004-11-25 10:19 ` Herbert Xu
0 siblings, 1 reply; 5+ messages in thread
From: David Stevens @ 2004-11-24 22:03 UTC (permalink / raw)
To: Luiz Fernando Capitulino; +Cc: akpm, David S. Miller, jgarzik, netdev
It's just a style issue, so maybe you'll disagree, but I prefer:
if (!sock)
return err;
to your
if (!sock)
goto out;
...
out:
return err;
I think "return err" is more readable than "goto out/return err"
for
that path and having another "return err" for the out-with-put case isn't
a
terrible thing.
+-DLS
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch 10/13] net/socket.c::sys_bind() cleanup.
2004-11-24 22:03 ` David Stevens
@ 2004-11-25 10:19 ` Herbert Xu
0 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2004-11-25 10:19 UTC (permalink / raw)
To: David Stevens; +Cc: lcapitulino, akpm, davem, jgarzik, netdev
David Stevens <dlstevens@us.ibm.com> wrote:
> It's just a style issue, so maybe you'll disagree, but I prefer:
>
> if (!sock)
> return err;
>
> to your
>
> if (!sock)
> goto out;
> ...
> out:
> return err;
>
> I think "return err" is more readable than "goto out/return err"
> for
> that path and having another "return err" for the out-with-put case isn't
> a
> terrible thing.
When used in isolation you would be right. However when there
are multiple exit points then the goto is better because it
means that we have only one exit path. When you have multiple
exit paths it's very easy to get memory leaks and missing unlock's.
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-11-25 10:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-22 6:43 [patch 10/13] net/socket.c::sys_bind() cleanup akpm
2004-11-24 8:27 ` David S. Miller
2004-11-24 10:55 ` Luiz Fernando Capitulino
2004-11-24 22:03 ` David Stevens
2004-11-25 10:19 ` Herbert Xu
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).