s390/mm: Simplify gap clamping in mmap_base() using clamp()
Quoted 25 lines · Alexander Gordeev
Quoted 24 lines · Qasim Ijaz
mmap_base()has logic to ensure that the variable "gap" stays within the range defined by "gap_min" and "gap_max". Replace this with theclamp()macro to shorten and simplify code.Signed-off-by Qasim Ijaz <[email protected]>--- arch/s390/mm/mmap.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)arch/s390/mm/mmap.c +1
-5@@ -63,11 +63,7 @@ static inline unsigned long mmap_base(unsigned long rnd,*/ gap_min =SZ_128M ; gap_max = (STACK_TOP /6 ) *5 ; - -if (gap < gap_min) - gap = gap_min; -else if (gap > gap_max) - gap = gap_max; + gap =clamp (gap, gap_min, gap_max);
Quoted 6 lines
arch/s390/mm/mmap.c static inline unsigned long mmap_base(unsigned long rnd, · line 69
Quoted 2 lines
arch/s390/mm/mmap.c +0
-0return PAGE_ALIGN (STACK_TOP - gap - rnd); }Whenever possible I personally prefer branches over ternary operators. But if one wants to clump it in one line, then
gap_minandgap_maxare also redundant.
Thank you for the feedback Alexander, would you like me to send a v2 patch without the gap_min and gap_max variables as you suggested?
Quoted 2 lines
Thanks!