[PATCH 05/18] fs/mpage: use accessor function to translate page index to sectors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use accessor functions to translate between page index and block sectors
and ensure the resulting buffer size is calculated correctly.

Signed-off-by: Hannes Reinecke <hare@xxxxxxx>
---
 fs/mpage.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/fs/mpage.c b/fs/mpage.c
index c9d9fdadb500..26460afd829a 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -168,7 +168,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
 	sector_t last_block;
 	sector_t last_block_in_file;
 	sector_t blocks[MAX_BUF_PER_PAGE];
-	unsigned page_block;
+	unsigned num_blocks, page_block;
 	unsigned first_hole = blocks_per_folio;
 	struct block_device *bdev = NULL;
 	int length;
@@ -189,8 +189,12 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
 	if (folio_buffers(folio))
 		goto confused;
 
-	block_in_file = (sector_t)folio->index << (PAGE_SHIFT - blkbits);
-	last_block = block_in_file + args->nr_pages * blocks_per_folio;
+	block_in_file = block_index_to_sector(folio->index, blkbits);
+	if (blkbits > PAGE_SHIFT)
+		num_blocks = args->nr_pages >> (blkbits - PAGE_SHIFT);
+	else
+		num_blocks = args->nr_pages * blocks_per_folio;
+	last_block = block_in_file + num_blocks;
 	last_block_in_file = (i_size_read(inode) + blocksize - 1) >> blkbits;
 	if (last_block > last_block_in_file)
 		last_block = last_block_in_file;
@@ -277,7 +281,7 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args)
 	}
 
 	if (first_hole != blocks_per_folio) {
-		folio_zero_segment(folio, first_hole << blkbits, PAGE_SIZE);
+		folio_zero_segment(folio, first_hole << blkbits, folio_size(folio));
 		if (first_hole == 0) {
 			folio_mark_uptodate(folio);
 			folio_unlock(folio);
@@ -543,7 +547,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc,
 	 * The page has no buffers: map it to disk
 	 */
 	BUG_ON(!folio_test_uptodate(folio));
-	block_in_file = (sector_t)folio->index << (PAGE_SHIFT - blkbits);
+	block_in_file = block_index_to_sector(folio->index, blkbits);
 	/*
 	 * Whole page beyond EOF? Skip allocating blocks to avoid leaking
 	 * space.
-- 
2.35.3




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux