signalfd: convert do_signalfd4() to FD_ADD()

Link: https://patch.msgid.link/20251123-work-fd-prepare-v4-14-b6efa1706cfd@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2025-11-23 17:33:32 +01:00
parent 360fbf808a
commit 5b755da105
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2
1 changed files with 11 additions and 18 deletions

View File

@ -250,8 +250,6 @@ static const struct file_operations signalfd_fops = {
static int do_signalfd4(int ufd, sigset_t *mask, int flags) static int do_signalfd4(int ufd, sigset_t *mask, int flags)
{ {
struct signalfd_ctx *ctx;
/* Check the SFD_* constants for consistency. */ /* Check the SFD_* constants for consistency. */
BUILD_BUG_ON(SFD_CLOEXEC != O_CLOEXEC); BUILD_BUG_ON(SFD_CLOEXEC != O_CLOEXEC);
BUILD_BUG_ON(SFD_NONBLOCK != O_NONBLOCK); BUILD_BUG_ON(SFD_NONBLOCK != O_NONBLOCK);
@ -263,7 +261,8 @@ static int do_signalfd4(int ufd, sigset_t *mask, int flags)
signotset(mask); signotset(mask);
if (ufd == -1) { if (ufd == -1) {
struct file *file; int fd;
struct signalfd_ctx *ctx __free(kfree) = NULL;
ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx) if (!ctx)
@ -271,22 +270,16 @@ static int do_signalfd4(int ufd, sigset_t *mask, int flags)
ctx->sigmask = *mask; ctx->sigmask = *mask;
ufd = get_unused_fd_flags(flags & O_CLOEXEC); fd = FD_ADD(flags & O_CLOEXEC,
if (ufd < 0) { anon_inode_getfile_fmode(
kfree(ctx); "[signalfd]", &signalfd_fops, ctx,
return ufd; O_RDWR | (flags & O_NONBLOCK), FMODE_NOWAIT));
} if (fd >= 0)
retain_and_null_ptr(ctx);
file = anon_inode_getfile_fmode("[signalfd]", &signalfd_fops, return fd;
ctx, O_RDWR | (flags & O_NONBLOCK),
FMODE_NOWAIT);
if (IS_ERR(file)) {
put_unused_fd(ufd);
kfree(ctx);
return PTR_ERR(file);
}
fd_install(ufd, file);
} else { } else {
struct signalfd_ctx *ctx;
CLASS(fd, f)(ufd); CLASS(fd, f)(ufd);
if (fd_empty(f)) if (fd_empty(f))
return -EBADF; return -EBADF;