diff mbox series

[RESEND,V5,1/2] mm: fadvise: move 'endbyte' calculations to helper function

Message ID ff8e0629a5f6ad8cd1efd860d3218e0972edb9cb.1648706231.git.quic_charante@quicinc.com (mailing list archive)
State New
Headers show
Series mm: shmem: support POSIX_FADV_[WILL|DONT]NEED for shmem files | expand

Commit Message

Charan Teja Kalla March 31, 2022, 6:38 a.m. UTC
From: Charan Teja Reddy <quic_charante@quicinc.com>

Move the 'endbyte' calculations that determines last byte that fadvise
can to a helper function. This is a preparatory change made for
shmem_fadvise() functionality in the next patch. No functional changes
in this patch.

Signed-off-by: Charan Teja Reddy <quic_charante@quicinc.com>
---
Changes in V5:
 -- Moved the 'endbyte' calculation to a helper function.
 -- This patch is newly raised in V5 thus no change exists from v1 to v4.

 mm/fadvise.c  | 11 +----------
 mm/internal.h | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/mm/fadvise.c b/mm/fadvise.c
index 338f160..0c82be2 100644
--- a/mm/fadvise.c
+++ b/mm/fadvise.c
@@ -65,16 +65,7 @@  int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice)
 		return 0;
 	}
 
-	/*
-	 * Careful about overflows. Len == 0 means "as much as possible".  Use
-	 * unsigned math because signed overflows are undefined and UBSan
-	 * complains.
-	 */
-	endbyte = (u64)offset + (u64)len;
-	if (!len || endbyte < len)
-		endbyte = -1;
-	else
-		endbyte--;		/* inclusive */
+	endbyte = fadvise_calc_endbyte(offset, len);
 
 	switch (advice) {
 	case POSIX_FADV_NORMAL:
diff --git a/mm/internal.h b/mm/internal.h
index 58dc6ad..b02f07e 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -546,6 +546,27 @@  static inline void vunmap_range_noflush(unsigned long start, unsigned long end)
 #endif /* !CONFIG_MMU */
 
 /*
+ * Helper function to get the endbyte of a file that fadvise can operate on.
+ */
+static inline loff_t fadvise_calc_endbyte(loff_t offset, loff_t len)
+{
+	loff_t endbyte;
+
+	/*
+	 * Careful about overflows. Len == 0 means "as much as possible".  Use
+	 * unsigned math because signed overflows are undefined and UBSan
+	 * complains.
+	 */
+	endbyte = (u64)offset + (u64)len;
+	if (!len || endbyte < len)
+		endbyte = -1;
+	else
+		endbyte--;		/* inclusive */
+
+	return endbyte;
+}
+
+/*
  * Return the mem_map entry representing the 'offset' subpage within
  * the maximally aligned gigantic page 'base'.  Handle any discontiguity
  * in the mem_map at MAX_ORDER_NR_PAGES boundaries.