net/handshake: convert handshake_nl_accept_doit() to FD_PREPARE()

Link: https://patch.msgid.link/20251123-work-fd-prepare-v4-27-b6efa1706cfd@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2025-11-23 17:33:45 +01:00
parent 910c361f9a
commit fe67b063f6
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2

View File

@ -93,7 +93,7 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info)
struct handshake_net *hn = handshake_pernet(net); struct handshake_net *hn = handshake_pernet(net);
struct handshake_req *req = NULL; struct handshake_req *req = NULL;
struct socket *sock; struct socket *sock;
int class, fd, err; int class, err;
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
if (!hn) if (!hn)
@ -106,26 +106,24 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info)
err = -EAGAIN; err = -EAGAIN;
req = handshake_req_next(hn, class); req = handshake_req_next(hn, class);
if (!req) if (req) {
goto out_status;
sock = req->hr_sk->sk_socket; sock = req->hr_sk->sk_socket;
fd = get_unused_fd_flags(O_CLOEXEC);
if (fd < 0) { FD_PREPARE(fdf, O_CLOEXEC, sock->file);
err = fd; if (fdf.err) {
err = fdf.err;
goto out_complete; goto out_complete;
} }
err = req->hr_proto->hp_accept(req, info, fd); get_file(sock->file); /* FD_PREPARE() consumes a reference. */
if (err) { err = req->hr_proto->hp_accept(req, info, fd_prepare_fd(fdf));
put_unused_fd(fd); if (err)
goto out_complete; goto out_complete; /* Automatic cleanup handles fput */
}
fd_install(fd, get_file(sock->file)); trace_handshake_cmd_accept(net, req, req->hr_sk, fd_prepare_fd(fdf));
fd_publish(fdf);
trace_handshake_cmd_accept(net, req, req->hr_sk, fd);
return 0; return 0;
}
out_complete: out_complete:
handshake_complete(req, -EIO, NULL); handshake_complete(req, -EIO, NULL);