@@ -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:
@@ -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.