mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-09 06:33:34 +00:00
net: streamline __sys_setsockopt
Return early when sockfd_lookup_light fails to reduce a level of indentation for most of the function body. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
a06d30ae7a
commit
4a3672993f
65
net/socket.c
65
net/socket.c
@ -2107,43 +2107,40 @@ static int __sys_setsockopt(int fd, int level, int optname,
|
||||
return -EINVAL;
|
||||
|
||||
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
||||
if (sock != NULL) {
|
||||
err = security_socket_setsockopt(sock, level, optname);
|
||||
if (err)
|
||||
goto out_put;
|
||||
if (!sock)
|
||||
return err;
|
||||
|
||||
err = BPF_CGROUP_RUN_PROG_SETSOCKOPT(sock->sk, &level,
|
||||
&optname, optval, &optlen,
|
||||
&kernel_optval);
|
||||
err = security_socket_setsockopt(sock, level, optname);
|
||||
if (err)
|
||||
goto out_put;
|
||||
|
||||
if (err < 0) {
|
||||
goto out_put;
|
||||
} else if (err > 0) {
|
||||
err = 0;
|
||||
goto out_put;
|
||||
}
|
||||
|
||||
if (kernel_optval) {
|
||||
set_fs(KERNEL_DS);
|
||||
optval = (char __user __force *)kernel_optval;
|
||||
}
|
||||
|
||||
if (level == SOL_SOCKET && !sock_use_custom_sol_socket(sock))
|
||||
err =
|
||||
sock_setsockopt(sock, level, optname, optval,
|
||||
optlen);
|
||||
else
|
||||
err =
|
||||
sock->ops->setsockopt(sock, level, optname, optval,
|
||||
optlen);
|
||||
|
||||
if (kernel_optval) {
|
||||
set_fs(oldfs);
|
||||
kfree(kernel_optval);
|
||||
}
|
||||
out_put:
|
||||
fput_light(sock->file, fput_needed);
|
||||
err = BPF_CGROUP_RUN_PROG_SETSOCKOPT(sock->sk, &level, &optname,
|
||||
optval, &optlen, &kernel_optval);
|
||||
if (err < 0)
|
||||
goto out_put;
|
||||
if (err > 0) {
|
||||
err = 0;
|
||||
goto out_put;
|
||||
}
|
||||
|
||||
if (kernel_optval) {
|
||||
set_fs(KERNEL_DS);
|
||||
optval = (char __user __force *)kernel_optval;
|
||||
}
|
||||
|
||||
if (level == SOL_SOCKET && !sock_use_custom_sol_socket(sock))
|
||||
err = sock_setsockopt(sock, level, optname, optval, optlen);
|
||||
else
|
||||
err = sock->ops->setsockopt(sock, level, optname, optval,
|
||||
optlen);
|
||||
|
||||
if (kernel_optval) {
|
||||
set_fs(oldfs);
|
||||
kfree(kernel_optval);
|
||||
}
|
||||
|
||||
out_put:
|
||||
fput_light(sock->file, fput_needed);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user