file: Rename __fcheck_files to files_lookup_fd_raw
authorEric W. Biederman <ebiederm@xmission.com>
Fri, 20 Nov 2020 23:14:24 +0000 (17:14 -0600)
committerEric W. Biederman <ebiederm@xmission.com>
Thu, 10 Dec 2020 18:39:54 +0000 (12:39 -0600)
The function fcheck despite it's comment is poorly named
as it has no callers that only check it's return value.
All of fcheck's callers use the returned file descriptor.
The same is true for fcheck_files and __fcheck_files.

A new less confusing name is needed.  In addition the names
of these functions are confusing as they do not report
the kind of locks that are needed to be held when these
functions are called making error prone to use them.

To remedy this I am making the base functio name lookup_fd
and will and prefixes and sufficies to indicate the rest
of the context.

Name the function (previously called __fcheck_files) that proceeds
from a struct files_struct, looks up the struct file of a file
descriptor, and requires it's callers to verify all of the appropriate
locks are held files_lookup_fd_raw.

The need for better names became apparent in the last round of
discussion of this set of changes[1].

[1] https://lkml.kernel.org/r/CAHk-=wj8BQbgJFLa+J0e=iT-1qpmCRTbPAJ8gd6MJQ=kbRPqyQ@mail.gmail.com
Link: https://lkml.kernel.org/r/20201120231441.29911-7-ebiederm@xmission.com
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
fs/file.c
include/linux/fdtable.h

index beae7c55c84ca0a0ec3a84979ab01966c9a71c0e..b5591efb87f56c5ef62ac70ca24fd5e638167a23 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -887,7 +887,7 @@ static unsigned long __fget_light(unsigned int fd, fmode_t mask)
        struct file *file;
 
        if (atomic_read(&files->count) == 1) {
-               file = __fcheck_files(files, fd);
+               file = files_lookup_fd_raw(files, fd);
                if (!file || unlikely(file->f_mode & mask))
                        return 0;
                return (unsigned long)file;
index 7cc9885044d92190cae94b6bce1a57034c5ac2d4..639933f37da9fbf4e3d0cd7b3ca1b052af8c5c52 100644 (file)
@@ -80,7 +80,7 @@ struct dentry;
 /*
  * The caller must ensure that fd table isn't shared or hold rcu or file lock
  */
-static inline struct file *__fcheck_files(struct files_struct *files, unsigned int fd)
+static inline struct file *files_lookup_fd_raw(struct files_struct *files, unsigned int fd)
 {
        struct fdtable *fdt = rcu_dereference_raw(files->fdt);
 
@@ -96,7 +96,7 @@ static inline struct file *fcheck_files(struct files_struct *files, unsigned int
        RCU_LOCKDEP_WARN(!rcu_read_lock_held() &&
                           !lockdep_is_held(&files->file_lock),
                           "suspicious rcu_dereference_check() usage");
-       return __fcheck_files(files, fd);
+       return files_lookup_fd_raw(files, fd);
 }
 
 /*