[PATCH] net: socket: Use fdget() and fdput()

From: ye.xingchen
Date: Fri May 05 2023 - 05:07:34 EST


From: Ye Xingchen <ye.xingchen@xxxxxxxxxx>

By using the fdget function, the socket object, can be quickly obtained
from the process's file descriptor table without the need to obtain the
file descriptor first before passing it as a parameter to the fget
function.

Signed-off-by: Ye Xingchen <ye.xingchen@xxxxxxxxxx>
---
net/socket.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/net/socket.c b/net/socket.c
index a7b4b37d86df..84daba774432 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -528,19 +528,18 @@ EXPORT_SYMBOL(sock_from_file);

struct socket *sockfd_lookup(int fd, int *err)
{
- struct file *file;
+ struct fd f = fdget(fd);
struct socket *sock;

- file = fget(fd);
- if (!file) {
+ if (!f.file) {
*err = -EBADF;
return NULL;
}

- sock = sock_from_file(file);
+ sock = sock_from_file(f.file);
if (!sock) {
*err = -ENOTSOCK;
- fput(file);
+ fdput(f);
}
return sock;
}
--
2.25.1