Skip to content

Commit

Permalink
mm: Handle 0 flags in _calc_vm_trans() macro
Browse files Browse the repository at this point in the history
_calc_vm_trans() does not handle the situation when some of the passed
flags are 0 (which can happen if these VM flags do not make sense for
the architecture). Improve the _calc_vm_trans() macro to return 0 in
such situation. Since all passed flags are constant, this does not add
any runtime overhead.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
  • Loading branch information
Jan Kara authored and Dan Williams committed Nov 3, 2017
1 parent 8a5776a commit 592e254
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/linux/mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ static inline bool arch_validate_prot(unsigned long prot)
* ("bit1" and "bit2" must be single bits)
*/
#define _calc_vm_trans(x, bit1, bit2) \
((!(bit1) || !(bit2)) ? 0 : \
((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
: ((x) & (bit1)) / ((bit1) / (bit2)))
: ((x) & (bit1)) / ((bit1) / (bit2))))

/*
* Combine the mmap "prot" argument into "vm_flags" used internally.
Expand Down

0 comments on commit 592e254

Please sign in to comment.