]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
convert cachestat(2)
authorAl Viro <viro@zeniv.linux.org.uk>
Tue, 23 Jul 2024 01:59:30 +0000 (21:59 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 3 Nov 2024 06:28:07 +0000 (01:28 -0500)
fdput() can be transposed with copy_to_user()

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
mm/filemap.c

index 36d22968be9a1e10da42927dd627d3f22c3a747b..5f2504428f3dfaa55977482d4b57d287db708b1d 100644 (file)
@@ -4421,31 +4421,25 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd,
                struct cachestat_range __user *, cstat_range,
                struct cachestat __user *, cstat, unsigned int, flags)
 {
-       struct fd f = fdget(fd);
+       CLASS(fd, f)(fd);
        struct address_space *mapping;
        struct cachestat_range csr;
        struct cachestat cs;
        pgoff_t first_index, last_index;
 
-       if (!fd_file(f))
+       if (fd_empty(f))
                return -EBADF;
 
        if (copy_from_user(&csr, cstat_range,
-                       sizeof(struct cachestat_range))) {
-               fdput(f);
+                       sizeof(struct cachestat_range)))
                return -EFAULT;
-       }
 
        /* hugetlbfs is not supported */
-       if (is_file_hugepages(fd_file(f))) {
-               fdput(f);
+       if (is_file_hugepages(fd_file(f)))
                return -EOPNOTSUPP;
-       }
 
-       if (flags != 0) {
-               fdput(f);
+       if (flags != 0)
                return -EINVAL;
-       }
 
        first_index = csr.off >> PAGE_SHIFT;
        last_index =
@@ -4453,7 +4447,6 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd,
        memset(&cs, 0, sizeof(struct cachestat));
        mapping = fd_file(f)->f_mapping;
        filemap_cachestat(mapping, first_index, last_index, &cs);
-       fdput(f);
 
        if (copy_to_user(cstat, &cs, sizeof(struct cachestat)))
                return -EFAULT;