Skip to content

Commit dc530c4

Browse files
mjguzikbrauner
authored andcommitted
fs: use debug-only asserts around fd allocation and install
This also restores the check which got removed in 52732bb ("fs/file.c: remove sanity_check and add likely/unlikely in alloc_fd()") for performance reasons -- they no longer apply with a debug-only variant. Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Link: https://lore.kernel.org/r/20250312161941.1261615-1-mjguzik@gmail.com Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 86f40fa commit dc530c4

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

fs/file.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags)
577577

578578
__set_open_fd(fd, fdt, flags & O_CLOEXEC);
579579
error = fd;
580+
VFS_BUG_ON(rcu_access_pointer(fdt->fd[fd]) != NULL);
580581

581582
out:
582583
spin_unlock(&files->file_lock);
@@ -642,15 +643,15 @@ void fd_install(unsigned int fd, struct file *file)
642643
rcu_read_unlock_sched();
643644
spin_lock(&files->file_lock);
644645
fdt = files_fdtable(files);
645-
WARN_ON(fdt->fd[fd] != NULL);
646+
VFS_BUG_ON(rcu_access_pointer(fdt->fd[fd]) != NULL);
646647
rcu_assign_pointer(fdt->fd[fd], file);
647648
spin_unlock(&files->file_lock);
648649
return;
649650
}
650651
/* coupled with smp_wmb() in expand_fdtable() */
651652
smp_rmb();
652653
fdt = rcu_dereference_sched(files->fdt);
653-
BUG_ON(fdt->fd[fd] != NULL);
654+
VFS_BUG_ON(rcu_access_pointer(fdt->fd[fd]) != NULL);
654655
rcu_assign_pointer(fdt->fd[fd], file);
655656
rcu_read_unlock_sched();
656657
}

0 commit comments

Comments
 (0)