Skip to contentSkip to conversation

mm/mseal: use min/max in mseal_apply

PATCH Applied Thorsten Blum 6 participants 6 messages May 3 – May 9

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/mseal: use min/max in mseal_apply

Use the type-checked min()/max() macros instead of MIN()/MAX(), which are supposed to be used "for obvious constants only".

---
 mm/mseal.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/mseal.c +3 -2
index e2093ae3d25c..9781647483d1 100644
@@ -8,6 +8,7 @@
  */
 
 #include <linux/mempolicy.h>
+#include <linux/minmax.h>
 #include <linux/mman.h>
 #include <linux/mm.h>
 #include <linux/mm_inline.h>
@@ -65,8 +66,8 @@ static int mseal_apply(struct mm_struct *mm,
 		prev = vma;
 
 	for_each_vma_range(vmi, vma, end) {
-		const unsigned long curr_start = MAX(vma->vm_start, start);
-		const unsigned long curr_end = MIN(vma->vm_end, end);
+		const unsigned long curr_start = max(vma->vm_start, start);
+		const unsigned long curr_end = min(vma->vm_end, end);
 
 		if (!vma_test(vma, VMA_SEALED_BIT)) {
 			vma_flags_t vma_flags = vma->flags;
#2 lore raw
Quoted 5 lines · On Sun, 3 May 2026 21:58:57 +0100 Pedro Falcato <[email protected]> wrote:
Quoted 2 lines · Thorsten Blum

Use the type-checked min()/max() macros instead of MIN()/MAX(), which are supposed to be used "for obvious constants only".

Gotta love these macros... FYI this isn't the only wrong usage in the kernel.

I failed to persuade Linus to include a test for __builtin_constant_p((a)|(b)) :-)

-- David

Quoted 6 lines
Quoted 3 lines
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Thorsten Blum
Quoted 4 lines · Thorsten Blum

Use the type-checked min()/max() macros instead of MIN()/MAX(), which are supposed to be used "for obvious constants only".

Oops my bad :)

LGTM, so:

Quoted 27 lines
---
 mm/mseal.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
mm/mseal.c +3 -2
index e2093ae3d25c..9781647483d1 100644
@@ -8,6 +8,7 @@
  */
 
 #include <linux/mempolicy.h>
+#include <linux/minmax.h>
 #include <linux/mman.h>
 #include <linux/mm.h>
 #include <linux/mm_inline.h>
@@ -65,8 +66,8 @@ static int mseal_apply(struct mm_struct *mm,
 		prev = vma;
 
 	for_each_vma_range(vmi, vma, end) {
-		const unsigned long curr_start = MAX(vma->vm_start, start);
-		const unsigned long curr_end = MIN(vma->vm_end, end);
+		const unsigned long curr_start = max(vma->vm_start, start);
+		const unsigned long curr_end = min(vma->vm_end, end);
 
 		if (!vma_test(vma, VMA_SEALED_BIT)) {
 			vma_flags_t vma_flags = vma->flags;