[Devel] [PATCH rh7 3/5] mm: cleanup size checks in filemap_fault() and filemap_map_pages()
Andrey Ryabinin
aryabinin at virtuozzo.com
Wed Feb 26 16:49:43 MSK 2020
From: "Kirill A. Shutemov" <kirill.shutemov at linux.intel.com>
Minor cleanups:
- 'size' variable is now in bytes, not pages;
- use round_up(): it should be easier to read.
Signed-off-by: Kirill A. Shutemov <kirill.shutemov at linux.intel.com>
Cc: Linus Torvalds <torvalds at linux-foundation.org>
Cc: Mel Gorman <mgorman at suse.de>
Cc: Rik van Riel <riel at redhat.com>
Cc: Andi Kleen <ak at linux.intel.com>
Cc: Matthew Wilcox <matthew.r.wilcox at intel.com>
Cc: Dave Hansen <dave.hansen at linux.intel.com>
Cc: Alexander Viro <viro at zeniv.linux.org.uk>
Cc: Dave Chinner <david at fromorbit.com>
Cc: Ning Qu <quning at gmail.com>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
https://jira.sw.ru/browse/PSBM-101300
(cherry picked from commit 99e3e53f4e0fd807607bf381e14f6de8feedd383)
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
mm/filemap.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/mm/filemap.c b/mm/filemap.c
index 2ba7ef844af6..bbddfeb2675d 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2285,11 +2285,11 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
struct inode *inode = mapping->host;
pgoff_t offset = vmf->pgoff;
struct page *page;
- pgoff_t size;
+ loff_t size;
int ret = 0;
- size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
- if (offset >= size)
+ size = round_up(i_size_read(inode), PAGE_CACHE_SIZE);
+ if (offset >= size >> PAGE_CACHE_SHIFT)
return VM_FAULT_SIGBUS;
/*
@@ -2350,8 +2350,8 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
* Found the page and have a reference on it.
* We must recheck i_size under page lock.
*/
- size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
- if (unlikely(offset >= size)) {
+ size = round_up(i_size_read(inode), PAGE_CACHE_SIZE);
+ if (unlikely(offset >= size >> PAGE_CACHE_SHIFT)) {
unlock_page(page);
page_cache_release(page);
return VM_FAULT_SIGBUS;
@@ -2455,8 +2455,8 @@ void filemap_map_pages(struct vm_area_struct *vma, struct vm_fault *vmf)
if (page->mapping != mapping || !PageUptodate(page))
goto unlock;
- size = i_size_read(mapping->host) + PAGE_CACHE_SIZE - 1;
- if (page->index >= size >> PAGE_CACHE_SHIFT)
+ size = round_up(i_size_read(mapping->host), PAGE_CACHE_SIZE);
+ if (page->index >= size >> PAGE_CACHE_SHIFT)
goto unlock;
pte = vmf->pte + page->index - vmf->pgoff;
--
2.24.1
More information about the Devel
mailing list