From: Qasim Ijaz Date: Tue, 4 Feb 2025 16:25:08 +0000 (+0000) Subject: s390/mm: Simplify gap clamping in mmap_base() using clamp() X-Git-Tag: v6.15-rc1~113^2~34 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a702b633c0649eef5249e0355ecfb60567e4dbf2;p=thirdparty%2Fkernel%2Flinux.git s390/mm: Simplify gap clamping in mmap_base() using clamp() mmap_base() has logic to ensure that the variable "gap" stays within the range defined by "gap_min" and "gap_max". Replace this with the clamp() macro to shorten and simplify code. Signed-off-by: Qasim Ijaz Link: https://lore.kernel.org/r/20250204162508.12335-1-qasdev00@gmail.com Reviewed-by: Vasily Gorbik [gor@linux.ibm.com: also remove the gap_min and gap_max variables] Signed-off-by: Vasily Gorbik --- diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c index 76f376876e0d9..40a526d28184b 100644 --- a/arch/s390/mm/mmap.c +++ b/arch/s390/mm/mmap.c @@ -51,7 +51,6 @@ static inline unsigned long mmap_base(unsigned long rnd, { unsigned long gap = rlim_stack->rlim_cur; unsigned long pad = stack_maxrandom_size() + stack_guard_gap; - unsigned long gap_min, gap_max; /* Values close to RLIM_INFINITY can overflow. */ if (gap + pad > gap) @@ -61,13 +60,7 @@ static inline unsigned long mmap_base(unsigned long rnd, * Top of mmap area (just below the process stack). * Leave at least a ~128 MB hole. */ - 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, SZ_128M, (STACK_TOP / 6) * 5); return PAGE_ALIGN(STACK_TOP - gap - rnd); }