The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH RESEND] x86/mm: Replace manual gap bounding with clamp()
@ 2025-02-15 12:52 Qasim Ijaz
  2025-02-21 14:49 ` [tip: x86/mm] x86/mm: Replace open-coded " tip-bot2 for Qasim Ijaz
  0 siblings, 1 reply; 2+ messages in thread
From: Qasim Ijaz @ 2025-02-15 12:52 UTC (permalink / raw)
  To: dave.hansen, luto, peterz, tglx, mingo, bp, hpa, x86; +Cc: linux-kernel

Rather than manually bounding gap between gap_min and gap_max,
use the clamp() macro to make the code more concise.

Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
---
 arch/x86/mm/mmap.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
index b8a6ffffb451..5ed2109211da 100644
--- a/arch/x86/mm/mmap.c
+++ b/arch/x86/mm/mmap.c
@@ -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);
 }
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [tip: x86/mm] x86/mm: Replace open-coded gap bounding with clamp()
  2025-02-15 12:52 [PATCH RESEND] x86/mm: Replace manual gap bounding with clamp() Qasim Ijaz
@ 2025-02-21 14:49 ` tip-bot2 for Qasim Ijaz
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Qasim Ijaz @ 2025-02-21 14:49 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Qasim Ijaz, Ingo Molnar, x86, linux-kernel

The following commit has been merged into the x86/mm branch of tip:

Commit-ID:     282f395244df3663dc24e97a86087431c9192513
Gitweb:        https://git.kernel.org/tip/282f395244df3663dc24e97a86087431c9192513
Author:        Qasim Ijaz <qasdev00@gmail.com>
AuthorDate:    Sat, 15 Feb 2025 12:52:49 
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Fri, 21 Feb 2025 15:33:57 +01:00

x86/mm: Replace open-coded gap bounding with clamp()

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 |  9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
index b8a6fff..5ed2109 100644
--- a/arch/x86/mm/mmap.c
+++ b/arch/x86/mm/mmap.c
@@ -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);
 }

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-21 14:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-15 12:52 [PATCH RESEND] x86/mm: Replace manual gap bounding with clamp() Qasim Ijaz
2025-02-21 14:49 ` [tip: x86/mm] x86/mm: Replace open-coded " tip-bot2 for Qasim Ijaz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox