Skip to content

Commit afb9917

Browse files
committed
Revert "net/socket: convert sock_map_fd() to FD_ADD()"
This reverts commit 245f0d1. When allocating a file sock_alloc_file() consumes the socket reference unconditionally which isn't correctly handled in the conversion. This can be fixed by massaging this appropriately but this is best left for next cycle. Reported-by: Xin Long <lucien.xin@gmail.com> Link: https://lore.kernel.org/CADvbK_ewub4ZZK-tZg8GBQbDFHWhd9a48C+AFXZ93pMsssCrUg@mail.gmail.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent b6cb3cc commit afb9917

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

net/socket.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,21 @@ EXPORT_SYMBOL(sock_alloc_file);
503503

504504
static int sock_map_fd(struct socket *sock, int flags)
505505
{
506-
int fd;
507-
508-
fd = FD_ADD(flags, sock_alloc_file(sock, flags, NULL));
509-
if (fd < 0)
506+
struct file *newfile;
507+
int fd = get_unused_fd_flags(flags);
508+
if (unlikely(fd < 0)) {
510509
sock_release(sock);
511-
return fd;
510+
return fd;
511+
}
512+
513+
newfile = sock_alloc_file(sock, flags, NULL);
514+
if (!IS_ERR(newfile)) {
515+
fd_install(fd, newfile);
516+
return fd;
517+
}
518+
519+
put_unused_fd(fd);
520+
return PTR_ERR(newfile);
512521
}
513522

514523
/**

0 commit comments

Comments
 (0)