Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

buffer: calculate block number inside folio_init_buffers()

The calculation of block from index doesn't work for devices with a block
size larger than PAGE_SIZE as we end up shifting by a negative number.
Instead, calculate the number of the first block from the folio's position
in the block device. We no longer need to pass sizebits to
grow_dev_folio().

Link: https://lkml.kernel.org/r/20231109210608.2252323-3-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Matthew Wilcox (Oracle) and committed by
Andrew Morton
382497ad 6d840a18

+6 -7
+6 -7
fs/buffer.c
··· 995 995 * Initialise the state of a blockdev folio's buffers. 996 996 */ 997 997 static sector_t folio_init_buffers(struct folio *folio, 998 - struct block_device *bdev, sector_t block, int size) 998 + struct block_device *bdev, unsigned size) 999 999 { 1000 1000 struct buffer_head *head = folio_buffers(folio); 1001 1001 struct buffer_head *bh = head; 1002 1002 bool uptodate = folio_test_uptodate(folio); 1003 + sector_t block = div_u64(folio_pos(folio), size); 1003 1004 sector_t end_block = blkdev_max_block(bdev, size); 1004 1005 1005 1006 do { ··· 1033 1032 * we succeeded, or the caller should retry. 1034 1033 */ 1035 1034 static bool grow_dev_folio(struct block_device *bdev, sector_t block, 1036 - pgoff_t index, unsigned size, int sizebits, gfp_t gfp) 1035 + pgoff_t index, unsigned size, gfp_t gfp) 1037 1036 { 1038 1037 struct inode *inode = bdev->bd_inode; 1039 1038 struct folio *folio; ··· 1048 1047 bh = folio_buffers(folio); 1049 1048 if (bh) { 1050 1049 if (bh->b_size == size) { 1051 - end_block = folio_init_buffers(folio, bdev, 1052 - (sector_t)index << sizebits, size); 1050 + end_block = folio_init_buffers(folio, bdev, size); 1053 1051 goto unlock; 1054 1052 } 1055 1053 ··· 1069 1069 */ 1070 1070 spin_lock(&inode->i_mapping->private_lock); 1071 1071 link_dev_buffers(folio, bh); 1072 - end_block = folio_init_buffers(folio, bdev, 1073 - (sector_t)index << sizebits, size); 1072 + end_block = folio_init_buffers(folio, bdev, size); 1074 1073 spin_unlock(&inode->i_mapping->private_lock); 1075 1074 unlock: 1076 1075 folio_unlock(folio); ··· 1104 1105 } 1105 1106 1106 1107 /* Create a folio with the proper size buffers */ 1107 - return grow_dev_folio(bdev, block, index, size, sizebits, gfp); 1108 + return grow_dev_folio(bdev, block, index, size, gfp); 1108 1109 } 1109 1110 1110 1111 static struct buffer_head *