The patch titled Subject: mm: fadvise: move 'endbyte' calculations to helper function has been added to the -mm mm-unstable branch. Its filename is mm-fadvise-move-endbyte-calculations-to-helper-function.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-fadvise-move-endbyte-calculations-to-helper-function.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Charan Teja Kalla <quic_charante@xxxxxxxxxxx> Subject: mm: fadvise: move 'endbyte' calculations to helper function Date: Tue, 14 Feb 2023 18:21:49 +0530 Patch series "mm: shmem: support POSIX_FADV_[WILL|DONT]NEED for shmem files", v7. This patchset aims to implement POSIX_FADV_WILLNEED and POSIX_FADV_DONTNEED advices to shmem files which can be helpful for the drivers who may want to manage the pages of shmem files on their own, like, that are created through shmem_file_setup[_with_mnt](). This patch (of 2): 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. Link: https://lkml.kernel.org/r/cover.1676378702.git.quic_charante@xxxxxxxxxxx Link: https://lkml.kernel.org/r/22de7e716051abbafc01fab9f479f4d5b03745ca.1676378702.git.quic_charante@xxxxxxxxxxx Signed-off-by: Charan Teja Kalla <quic_charante@xxxxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Hugh Dickins <hughd@xxxxxxxxxx> Cc: Mark Hemment <markhemm@xxxxxxxxxxxxxx> Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx> Cc: Pavankumar Kondeti <quic_pkondeti@xxxxxxxxxxx> Cc: Shakeel Butt <shakeelb@xxxxxxxxxx> Cc: Suren Baghdasaryan <surenb@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/fadvise.c | 11 +---------- mm/internal.h | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) --- a/mm/fadvise.c~mm-fadvise-move-endbyte-calculations-to-helper-function +++ a/mm/fadvise.c @@ -65,16 +65,7 @@ int generic_fadvise(struct file *file, l 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 = LLONG_MAX; - else - endbyte--; /* inclusive */ + endbyte = fadvise_calc_endbyte(offset, len); switch (advice) { case POSIX_FADV_NORMAL: --- a/mm/internal.h~mm-fadvise-move-endbyte-calculations-to-helper-function +++ a/mm/internal.h @@ -657,6 +657,27 @@ static inline void vunmap_range_noflush( } #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 = LLONG_MAX; + else + endbyte--; /* inclusive */ + + return endbyte; +} + /* Memory initialisation debug and verification */ enum mminit_level { MMINIT_WARNING, _ Patches currently in -mm which might be from quic_charante@xxxxxxxxxxx are mm-fadvise-move-endbyte-calculations-to-helper-function.patch mm-shmem-implement-posix_fadv_need-for-shmem.patch