* [PATCH] net: socket: Use fdget() and fdput()
@ 2023-05-05 9:06 ye.xingchen
2023-05-05 10:37 ` Eric Dumazet
2023-05-11 5:24 ` Al Viro
0 siblings, 2 replies; 3+ messages in thread
From: ye.xingchen @ 2023-05-05 9:06 UTC (permalink / raw)
To: davem; +Cc: edumazet, kuba, pabeni, netdev, linux-kernel
From: Ye Xingchen <ye.xingchen@zte.com.cn>
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@zte.com.cn>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: socket: Use fdget() and fdput()
2023-05-05 9:06 [PATCH] net: socket: Use fdget() and fdput() ye.xingchen
@ 2023-05-05 10:37 ` Eric Dumazet
2023-05-11 5:24 ` Al Viro
1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2023-05-05 10:37 UTC (permalink / raw)
To: ye.xingchen; +Cc: davem, kuba, pabeni, netdev, linux-kernel
On Fri, May 5, 2023 at 11:06 AM <ye.xingchen@zte.com.cn> wrote:
>
> From: Ye Xingchen <ye.xingchen@zte.com.cn>
>
> 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.
>
net-next is currently closed.
There are good reasons we have sockfd_lookup() and sockfd_lookup_light(),
you probably should take a deeper look at the difference between them.
> Signed-off-by: Ye Xingchen <ye.xingchen@zte.com.cn>
> ---
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: socket: Use fdget() and fdput()
2023-05-05 9:06 [PATCH] net: socket: Use fdget() and fdput() ye.xingchen
2023-05-05 10:37 ` Eric Dumazet
@ 2023-05-11 5:24 ` Al Viro
1 sibling, 0 replies; 3+ messages in thread
From: Al Viro @ 2023-05-11 5:24 UTC (permalink / raw)
To: ye.xingchen; +Cc: davem, edumazet, kuba, pabeni, netdev, linux-kernel
On Fri, May 05, 2023 at 05:06:41PM +0800, ye.xingchen@zte.com.cn wrote:
> 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.
> 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;
Suppose you've got that far. If descriptor table had been shared, you've
bumped the refcount of struct file. If it hadn't been, that refcount
had remained unchanged. And there is no way for the caller of this
function to tell one outcome from another.
That can't work.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-11 5:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-05 9:06 [PATCH] net: socket: Use fdget() and fdput() ye.xingchen
2023-05-05 10:37 ` Eric Dumazet
2023-05-11 5:24 ` Al Viro
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).