[PATCH] fixups
From: Lorenzo Stoakes
Date: Tue Apr 28 2026 - 02:48:30 EST
Signed-off-by: Lorenzo Stoakes <ljs@xxxxxxxxxx>
---
mm/madvise.c | 55 +++++++++++++++++++++-------------------------------
1 file changed, 22 insertions(+), 33 deletions(-)
diff --git a/mm/madvise.c b/mm/madvise.c
index ce238dd96f15..865fe7fb3d81 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -1834,45 +1834,31 @@ static void madvise_finish_tlb(struct madvise_behavior *madv_behavior)
tlb_finish_mmu(madv_behavior->tlb);
}
-static bool is_valid_madvise_range(unsigned long start, size_t len_in)
+/**
+ * check_input_range() - Check if the requested range is valid.
+ * @start: Start address of madvise-requested address range.
+ * @len_in: Length of madvise-requested address range.
+ *
+ * Returns: 0 if the input range is valid, otherwise an error code.
+ */
+static int check_input_range(unsigned long start, size_t len_in)
{
size_t len;
if (!PAGE_ALIGNED(start))
- return false;
+ return -EINVAL;
+
len = PAGE_ALIGN(len_in);
/* Check to see whether len was rounded up from small -ve to zero */
if (len_in && !len)
- return false;
+ return -EINVAL;
+ /* Overflow? */
if (start + len < start)
- return false;
-
- return true;
-}
+ return -EINVAL;
-/*
- * madvise_should_skip() - Return if the request is invalid or nothing.
- * @start: Start address of madvise-requested address range.
- * @len_in: Length of madvise-requested address range.
- * @err: Pointer to store an error code from the check.
- *
- * If the specified range is invalid or nothing would occur, we skip the
- * operation. This function returns true in these cases, otherwise false. In
- * the former case we store an error in @err.
- */
-static bool madvise_should_skip(unsigned long start, size_t len_in, int *err)
-{
- if (!is_valid_madvise_range(start, len_in)) {
- *err = -EINVAL;
- return true;
- }
- if (start + PAGE_ALIGN(len_in) == start) {
- *err = 0;
- return true;
- }
- return false;
+ return 0;
}
static bool is_madvise_populate(struct madvise_behavior *madv_behavior)
@@ -2010,12 +1996,13 @@ int do_madvise(struct mm_struct *mm, unsigned long start, size_t len_in, int beh
if (!madvise_behavior_valid(behavior))
return -EINVAL;
-
- if (madvise_should_skip(start, len_in, &error))
+ error = check_input_range(start, len_in);
+ if (error || !len_in)
return error;
error = madvise_lock(&madv_behavior);
if (error)
return error;
+
madvise_init_tlb(&madv_behavior);
error = madvise_do_behavior(start, len_in, &madv_behavior);
madvise_finish_tlb(&madv_behavior);
@@ -2054,10 +2041,12 @@ static ssize_t vector_madvise(struct mm_struct *mm, struct iov_iter *iter,
size_t len_in = iter_iov_len(iter);
int error;
- if (madvise_should_skip(start, len_in, &error))
- ret = error;
- else
+ error = check_input_range(start, len_in);
+ if (len_in && !error)
ret = madvise_do_behavior(start, len_in, &madv_behavior);
+ else
+ ret = error;
+
/*
* An madvise operation is attempting to restart the syscall,
* but we cannot proceed as it would not be correct to repeat
--
2.54.0