]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
s390/mm: Simplify gap clamping in mmap_base() using clamp()
authorQasim Ijaz <qasdev00@gmail.com>
Tue, 4 Feb 2025 16:25:08 +0000 (16:25 +0000)
committerVasily Gorbik <gor@linux.ibm.com>
Tue, 4 Mar 2025 16:18:08 +0000 (17:18 +0100)
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 <qasdev00@gmail.com>
Link: https://lore.kernel.org/r/20250204162508.12335-1-qasdev00@gmail.com
Reviewed-by: Vasily Gorbik <gor@linux.ibm.com>
[gor@linux.ibm.com: also remove the gap_min and gap_max variables]
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/mm/mmap.c

index 76f376876e0d90ebe163d7166ed5132e16096f30..40a526d28184b2649d663c6081f69a3462d3fc5e 100644 (file)
@@ -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);
 }