On 21.01.23 07:51, Christoph Hellwig wrote: > - if (btrfs_check_data_csum(inode, bbio, bio_offset, bv->bv_page, > - bv->bv_offset) < 0) > - return false; > + csum_expected = btrfs_csum_ptr(fs_info, bbio->csum, bio_offset); > + if (btrfs_check_sector_csum(fs_info, bv->bv_page, bv->bv_offset, csum, > + csum_expected)) > + goto zeroit; > return true; We could even go as far as that: diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index c63160cf135d..9f384551b722 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3449,13 +3449,6 @@ int btrfs_check_sector_csum(struct btrfs_fs_info *fs_info, struct page *page, return 0; } -static u8 *btrfs_csum_ptr(const struct btrfs_fs_info *fs_info, u8 *csums, u64 offset) -{ - u64 offset_in_sectors = offset >> fs_info->sectorsize_bits; - - return csums + offset_in_sectors * fs_info->csum_size; -} - /* * btrfs_data_csum_ok - verify the checksum of single data sector * @bbio: btrfs_io_bio which contains the csum @@ -3493,7 +3486,8 @@ bool btrfs_data_csum_ok(struct btrfs_bio *bbio, struct btrfs_device *dev, return true; } - csum_expected = btrfs_csum_ptr(fs_info, bbio->csum, bio_offset); + csum_expected = bbio->csum + (bio_offset >> fs_info->sectorsize_bits) * + fs_info->csum_size; if (btrfs_check_sector_csum(fs_info, bv->bv_page, bv->bv_offset, csum, csum_expected)) goto zeroit; Anyways that's splitting hairs, Reviewed-by: Johannes Thumshirn <johannes.thumshirn@xxxxxxx>