[PATCH 2/8] fs: use rest_of_page() macro where appropriate

Yury Norov
2026-03-04T01:27:30Z

Switch filesystem codebase to using the macro. No functional changes
intended.

Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
fs/ext4/verity.c | 3 +--
fs/f2fs/verity.c | 6 ++----
fs/fuse/dev.c | 4 ++--
fs/iomap/buffered-io.c | 2 +-
fs/nfs/pagelist.c | 2 +-
fs/remap_range.c | 3 +--
fs/xfs/scrub/xfile.c | 3 +--
7 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/fs/ext4/verity.c b/fs/ext4/verity.c
index ca61da53f313..3dc95581e4b1 100644
--- a/fs/ext4/verity.c
+++ b/fs/ext4/verity.c
@@ -74,8 +74,7 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,
return -EFBIG;

while (count) {
- size_t n = min_t(size_t, count,
- PAGE_SIZE - offset_in_page(pos));
+ size_t n = min_t(size_t, count, rest_of_page(pos));
struct folio *folio;
void *fsdata = NULL;
int res;
diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c
index 92ebcc19cab0..1c3403fbf2a8 100644
--- a/fs/f2fs/verity.c
+++ b/fs/f2fs/verity.c
@@ -44,8 +44,7 @@ static int pagecache_read(struct inode *inode, void *buf, size_t count,
loff_t pos)
{
while (count) {
- size_t n = min_t(size_t, count,
- PAGE_SIZE - offset_in_page(pos));
+ size_t n = min_t(size_t, count, rest_of_page(pos));
struct page *page;

page = read_mapping_page(inode->i_mapping, pos >> PAGE_SHIFT,
@@ -78,8 +77,7 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,
return -EFBIG;

while (count) {
- size_t n = min_t(size_t, count,
- PAGE_SIZE - offset_in_page(pos));
+ size_t n = min_t(size_t, count, rest_of_page(pos));
struct folio *folio;
void *fsdata = NULL;
int res;
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 0b0241f47170..efd7e6ca929e 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1157,8 +1157,8 @@ static int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop,
unsigned int copy = count;
unsigned int bytes_copied;

- if (folio_test_highmem(folio) && count > PAGE_SIZE - offset_in_page(offset))
- copy = PAGE_SIZE - offset_in_page(offset);
+ if (folio_test_highmem(folio) && count > rest_of_page(offset))
+ copy = rest_of_page(offset);

bytes_copied = fuse_copy_do(cs, &buf, &copy);
kunmap_local(mapaddr);
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index bc82083e420a..99e56ee6c3d6 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -852,7 +852,7 @@ static struct folio *__iomap_get_folio(struct iomap_iter *iter,
loff_t pos = iter->pos;

if (!mapping_large_folio_support(iter->inode->i_mapping))
- len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos));
+ len = min_t(size_t, len, rest_of_page(pos));

if (iter->iomap.flags & IOMAP_F_FOLIO_BATCH) {
struct folio *folio = folio_batch_next(iter->fbatch);
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index a9373de891c9..221a90f57812 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -60,7 +60,7 @@ static struct page *nfs_page_iter_page_get(struct nfs_page_iter_page *i)

if (i->count != req->wb_bytes) {
size_t base = i->count + req->wb_pgbase;
- size_t len = PAGE_SIZE - offset_in_page(base);
+ size_t len = rest_of_page(base);

page = nfs_page_to_page(req, base);
nfs_page_iter_page_advance(i, len);
diff --git a/fs/remap_range.c b/fs/remap_range.c
index 26afbbbfb10c..83f325e7f96b 100644
--- a/fs/remap_range.c
+++ b/fs/remap_range.c
@@ -199,8 +199,7 @@ static int vfs_dedupe_file_range_compare(struct file *src, loff_t srcoff,
while (len) {
struct folio *src_folio, *dst_folio;
void *src_addr, *dst_addr;
- loff_t cmp_len = min(PAGE_SIZE - offset_in_page(srcoff),
- PAGE_SIZE - offset_in_page(dstoff));
+ loff_t cmp_len = min(rest_of_page(srcoff), rest_of_page(dstoff));

cmp_len = min(cmp_len, len);
if (cmp_len <= 0)
diff --git a/fs/xfs/scrub/xfile.c b/fs/xfs/scrub/xfile.c
index 05581571854d..95707407aa6b 100644
--- a/fs/xfs/scrub/xfile.c
+++ b/fs/xfs/scrub/xfile.c
@@ -135,8 +135,7 @@ xfile_load(
* No data stored at this offset, just zero the output
* buffer until the next page boundary.
*/
- len = min_t(ssize_t, count,
- PAGE_SIZE - offset_in_page(pos));
+ len = min_t(ssize_t, count, rest_of_page(pos));
memset(buf, 0, len);
} else {
if (filemap_check_wb_err(inode->i_mapping, 0)) {
--
2.43.0