UPSTREAM: net: Remove the err argument from sock_from_file
Currently, the sock_from_file prototype takes an "err" pointer that is either not set or set to -ENOTSOCK IFF the returned socket is NULL. This makes the error redundant and it is ignored by a few callers. This patch simplifies the API by letting callers deduce the error based on whether the returned socket is NULL or not. Suggested-by: Al Viro <viro@zeniv.linux.org.uk> Change-Id: Ifd7fb27dae6eddcd1cc09410ac603ce6be09394b Signed-off-by: Florent Revest <revest@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: KP Singh <kpsingh@google.com> Link: https://lore.kernel.org/bpf/20201204113609.1850150-1-revest@google.com
This commit is contained in:
1 parent
252813af78
commit
5a122ec9ef
7 files changed
+14
-22
No files matched your search
+1
-2
@@ -420,12 +420,11 @@ static inline void ep_set_busy_poll_napi_id(struct epitem *epi)
|
|||||||
unsigned int napi_id;
|
unsigned int napi_id;
|
||||||
struct socket *sock;
|
struct socket *sock;
|
||||||
struct sock *sk;
|
struct sock *sk;
|
||||||
int err;
|
|
||||||
|
|
||||||
if (!net_busy_loop_on())
|
if (!net_busy_loop_on())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sock = sock_from_file(epi->ffd.file, &err);
|
sock = sock_from_file(epi->ffd.file);
|
||||||
if (!sock)
|
if (!sock)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -247,7 +247,7 @@ int sock_sendmsg(struct socket *sock, struct msghdr *msg);
|
|||||||
int sock_recvmsg(struct socket *sock, struct msghdr *msg, int flags);
|
int sock_recvmsg(struct socket *sock, struct msghdr *msg, int flags);
|
||||||
struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname);
|
struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname);
|
||||||
struct socket *sockfd_lookup(int fd, int *err);
|
struct socket *sockfd_lookup(int fd, int *err);
|
||||||
struct socket *sock_from_file(struct file *file, int *err);
|
struct socket *sock_from_file(struct file *file);
|
||||||
#define sockfd_put(sock) fput(sock->file)
|
#define sockfd_put(sock) fput(sock->file)
|
||||||
int net_ratelimit(void);
|
int net_ratelimit(void);
|
||||||
|
|
||||||
|
|||||||
@@ -72,9 +72,8 @@ struct update_classid_context {
|
|||||||
|
|
||||||
static int update_classid_sock(const void *v, struct file *file, unsigned n)
|
static int update_classid_sock(const void *v, struct file *file, unsigned n)
|
||||||
{
|
{
|
||||||
int err;
|
|
||||||
struct update_classid_context *ctx = (void *)v;
|
struct update_classid_context *ctx = (void *)v;
|
||||||
struct socket *sock = sock_from_file(file, &err);
|
struct socket *sock = sock_from_file(file);
|
||||||
|
|
||||||
if (sock) {
|
if (sock) {
|
||||||
spin_lock(&cgroup_sk_update_lock);
|
spin_lock(&cgroup_sk_update_lock);
|
||||||
|
|||||||
@@ -224,8 +224,7 @@ static ssize_t write_priomap(struct kernfs_open_file *of,
|
|||||||
|
|
||||||
static int update_netprio(const void *v, struct file *file, unsigned n)
|
static int update_netprio(const void *v, struct file *file, unsigned n)
|
||||||
{
|
{
|
||||||
int err;
|
struct socket *sock = sock_from_file(file);
|
||||||
struct socket *sock = sock_from_file(file, &err);
|
|
||||||
if (sock) {
|
if (sock) {
|
||||||
spin_lock(&cgroup_sk_update_lock);
|
spin_lock(&cgroup_sk_update_lock);
|
||||||
sock_cgroup_set_prioidx(&sock->sk->sk_cgrp_data,
|
sock_cgroup_set_prioidx(&sock->sk->sk_cgrp_data,
|
||||||
|
|||||||
+1
-1
@@ -294,7 +294,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Bump the usage count and install the file. */
|
/* Bump the usage count and install the file. */
|
||||||
sock = sock_from_file(fp[i], &err);
|
sock = sock_from_file(fp[i]);
|
||||||
if (sock) {
|
if (sock) {
|
||||||
sock_update_netprioidx(&sock->sk->sk_cgrp_data);
|
sock_update_netprioidx(&sock->sk->sk_cgrp_data);
|
||||||
sock_update_classid(&sock->sk->sk_cgrp_data);
|
sock_update_classid(&sock->sk->sk_cgrp_data);
|
||||||
|
|||||||
+1
-7
@@ -2725,14 +2725,8 @@ EXPORT_SYMBOL(sock_no_mmap);
|
|||||||
void __receive_sock(struct file *file)
|
void __receive_sock(struct file *file)
|
||||||
{
|
{
|
||||||
struct socket *sock;
|
struct socket *sock;
|
||||||
int error;
|
|
||||||
|
|
||||||
/*
|
sock = sock_from_file(file);
|
||||||
* The resulting value of "error" is ignored here since we only
|
|
||||||
* need to take action when the file is a socket and testing
|
|
||||||
* "sock" for NULL is sufficient.
|
|
||||||
*/
|
|
||||||
sock = sock_from_file(file, &error);
|
|
||||||
if (sock) {
|
if (sock) {
|
||||||
sock_update_netprioidx(&sock->sk->sk_cgrp_data);
|
sock_update_netprioidx(&sock->sk->sk_cgrp_data);
|
||||||
sock_update_classid(&sock->sk->sk_cgrp_data);
|
sock_update_classid(&sock->sk->sk_cgrp_data);
|
||||||
|
|||||||
+8
-7
@@ -461,17 +461,15 @@ static int sock_map_fd(struct socket *sock, int flags)
|
|||||||
/**
|
/**
|
||||||
* sock_from_file - Return the &socket bounded to @file.
|
* sock_from_file - Return the &socket bounded to @file.
|
||||||
* @file: file
|
* @file: file
|
||||||
* @err: pointer to an error code return
|
|
||||||
*
|
*
|
||||||
* On failure returns %NULL and assigns -ENOTSOCK to @err.
|
* On failure returns %NULL.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct socket *sock_from_file(struct file *file, int *err)
|
struct socket *sock_from_file(struct file *file)
|
||||||
{
|
{
|
||||||
if (file->f_op == &socket_file_ops)
|
if (file->f_op == &socket_file_ops)
|
||||||
return file->private_data; /* set in sock_map_fd */
|
return file->private_data; /* set in sock_map_fd */
|
||||||
|
|
||||||
*err = -ENOTSOCK;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(sock_from_file);
|
EXPORT_SYMBOL(sock_from_file);
|
||||||
@@ -500,9 +498,11 @@ struct socket *sockfd_lookup(int fd, int *err)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sock = sock_from_file(file, err);
|
sock = sock_from_file(file);
|
||||||
if (!sock)
|
if (!sock) {
|
||||||
|
*err = -ENOTSOCK;
|
||||||
fput(file);
|
fput(file);
|
||||||
|
}
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(sockfd_lookup);
|
EXPORT_SYMBOL(sockfd_lookup);
|
||||||
@@ -514,11 +514,12 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
|
|||||||
|
|
||||||
*err = -EBADF;
|
*err = -EBADF;
|
||||||
if (f.file) {
|
if (f.file) {
|
||||||
sock = sock_from_file(f.file, err);
|
sock = sock_from_file(f.file);
|
||||||
if (likely(sock)) {
|
if (likely(sock)) {
|
||||||
*fput_needed = f.flags & FDPUT_FPUT;
|
*fput_needed = f.flags & FDPUT_FPUT;
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
*err = -ENOTSOCK;
|
||||||
fdput(f);
|
fdput(f);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in new issue
Block a user