Skip to content

Commit b56baf5

Browse files
ukernelchrismason-xx
authored andcommitted
Minor fix for btrfs_csum_file_block.
Execution should goto label 'insert' when 'btrfs_next_leaf' return a non-zero value, otherwise the parameter 'slot' for 'btrfs_item_key_to_cpu' may be out of bounds. The original codes jump to label 'insert' only when 'btrfs_next_leaf' return a negative value. Signed-off-by: Chris Mason <[email protected]>
1 parent 689f934 commit b56baf5

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

fs/btrfs/file-item.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,11 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
178178
nritems = btrfs_header_nritems(path->nodes[0]);
179179
if (path->slots[0] >= nritems - 1) {
180180
ret = btrfs_next_leaf(root, path);
181-
if (ret == 1) {
181+
if (ret == 1)
182182
found_next = 1;
183-
} else if (ret == 0) {
184-
slot = 0;
185-
} else {
183+
if (ret != 0)
186184
goto insert;
187-
}
185+
slot = 0;
188186
}
189187
btrfs_item_key_to_cpu(path->nodes[0], &found_key, slot);
190188
if (found_key.objectid != objectid ||
@@ -238,7 +236,7 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
238236
csum_offset = 0;
239237
if (found_next) {
240238
u64 tmp = min((u64)i_size_read(inode), next_offset);
241-
tmp -= offset + root->sectorsize - 1;
239+
tmp -= offset & ~((u64)root->sectorsize -1);
242240
tmp >>= root->fs_info->sb->s_blocksize_bits;
243241
tmp = max((u64)1, tmp);
244242
tmp = min(tmp, (u64)MAX_CSUM_ITEMS(root));

0 commit comments

Comments
 (0)