Skip to content

Commit 65c8941

Browse files
author
Al Viro
committed
convert cachestat(2)
fdput() can be transposed with copy_to_user() Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 20d9eb3 commit 65c8941

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

mm/filemap.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4421,39 +4421,32 @@ SYSCALL_DEFINE4(cachestat, unsigned int, fd,
44214421
struct cachestat_range __user *, cstat_range,
44224422
struct cachestat __user *, cstat, unsigned int, flags)
44234423
{
4424-
struct fd f = fdget(fd);
4424+
CLASS(fd, f)(fd);
44254425
struct address_space *mapping;
44264426
struct cachestat_range csr;
44274427
struct cachestat cs;
44284428
pgoff_t first_index, last_index;
44294429

4430-
if (!fd_file(f))
4430+
if (fd_empty(f))
44314431
return -EBADF;
44324432

44334433
if (copy_from_user(&csr, cstat_range,
4434-
sizeof(struct cachestat_range))) {
4435-
fdput(f);
4434+
sizeof(struct cachestat_range)))
44364435
return -EFAULT;
4437-
}
44384436

44394437
/* hugetlbfs is not supported */
4440-
if (is_file_hugepages(fd_file(f))) {
4441-
fdput(f);
4438+
if (is_file_hugepages(fd_file(f)))
44424439
return -EOPNOTSUPP;
4443-
}
44444440

4445-
if (flags != 0) {
4446-
fdput(f);
4441+
if (flags != 0)
44474442
return -EINVAL;
4448-
}
44494443

44504444
first_index = csr.off >> PAGE_SHIFT;
44514445
last_index =
44524446
csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT;
44534447
memset(&cs, 0, sizeof(struct cachestat));
44544448
mapping = fd_file(f)->f_mapping;
44554449
filemap_cachestat(mapping, first_index, last_index, &cs);
4456-
fdput(f);
44574450

44584451
if (copy_to_user(cstat, &cs, sizeof(struct cachestat)))
44594452
return -EFAULT;

0 commit comments

Comments
 (0)