]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/mm: Replace open-coded gap bounding with clamp()
authorQasim Ijaz <qasdev00@gmail.com>
Sat, 15 Feb 2025 12:52:49 +0000 (12:52 +0000)
committerIngo Molnar <mingo@kernel.org>
Fri, 21 Feb 2025 14:33:57 +0000 (15:33 +0100)
Rather than manually bounding gap between gap_min and gap_max,
use the well-known clamp() macro to make the code easier to read.

Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20250215125249.10729-1-qasdev00@gmail.com
arch/x86/mm/mmap.c

index b8a6ffffb4519cd77f6a540562ef6d3efa4e7b0f..5ed2109211dab87ed435c09948a4ba266a1f0300 100644 (file)
@@ -84,7 +84,6 @@ static unsigned long mmap_base(unsigned long rnd, unsigned long task_size,
 {
        unsigned long gap = rlim_stack->rlim_cur;
        unsigned long pad = stack_maxrandom_size(task_size) + stack_guard_gap;
-       unsigned long gap_min, gap_max;
 
        /* Values close to RLIM_INFINITY can overflow. */
        if (gap + pad > gap)
@@ -94,13 +93,7 @@ static unsigned long mmap_base(unsigned long rnd, unsigned long task_size,
         * Top of mmap area (just below the process stack).
         * Leave an at least ~128 MB hole with possible stack randomization.
         */
-       gap_min = SIZE_128M;
-       gap_max = (task_size / 6) * 5;
-
-       if (gap < gap_min)
-               gap = gap_min;
-       else if (gap > gap_max)
-               gap = gap_max;
+       gap = clamp(gap, SIZE_128M, (task_size / 6) * 5);
 
        return PAGE_ALIGN(task_size - gap - rnd);
 }