Skip to content

Commit

Permalink
mm/mmap.c: optimization of do_mmap_pgoff function
Browse files Browse the repository at this point in the history
The simple check for zero length memory mapping may be performed
earlier.  So that in case of zero length memory mapping some unnecessary
code is not executed at all.  It does not make the code less readable
and saves some CPU cycles.

Signed-off-by: Piotr Kwapulinski <kwapulinski.piotr@gmail.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Acked-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Piotr Kwapulinski authored and Linus Torvalds committed Jun 25, 2015
1 parent 93ada57 commit e37609b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,

*populate = 0;

if (!len)
return -EINVAL;

/*
* Does the application expect PROT_READ to imply PROT_EXEC?
*
Expand All @@ -1268,9 +1271,6 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
prot |= PROT_EXEC;

if (!len)
return -EINVAL;

if (!(flags & MAP_FIXED))
addr = round_hint_to_min(addr);

Expand Down

0 comments on commit e37609b

Please sign in to comment.