Skip to content

Commit

Permalink
mm: cleanup size checks in filemap_fault() and filemap_map_pages()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Dave Chinner <[email protected]>
Cc: Ning Qu <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
kiryl authored and torvalds committed Apr 7, 2014
1 parent f182036 commit 99e3e53
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1953,11 +1953,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;

/*
Expand Down Expand Up @@ -2006,8 +2006,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;
Expand Down Expand Up @@ -2111,8 +2111,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;
Expand Down

0 comments on commit 99e3e53

Please sign in to comment.