mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
btrfs: switch to on-stack csum buffer in csum_tree_block
The maximum size of a checksum buffer is known, BTRFS_CSUM_SIZE, and we don't have to allocate it dynamically. This code path is not used at all as we have only the crc32c and use an on-stack buffer already. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
343e4fc1c6
commit
71a635516c
1 changed files with 3 additions and 13 deletions
|
@ -285,7 +285,7 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,
|
||||||
int verify)
|
int verify)
|
||||||
{
|
{
|
||||||
u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
|
u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
|
||||||
char *result = NULL;
|
char result[BTRFS_CSUM_SIZE];
|
||||||
unsigned long len;
|
unsigned long len;
|
||||||
unsigned long cur_len;
|
unsigned long cur_len;
|
||||||
unsigned long offset = BTRFS_CSUM_SIZE;
|
unsigned long offset = BTRFS_CSUM_SIZE;
|
||||||
|
@ -294,7 +294,6 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,
|
||||||
unsigned long map_len;
|
unsigned long map_len;
|
||||||
int err;
|
int err;
|
||||||
u32 crc = ~(u32)0;
|
u32 crc = ~(u32)0;
|
||||||
unsigned long inline_result;
|
|
||||||
|
|
||||||
len = buf->len - offset;
|
len = buf->len - offset;
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
|
@ -308,13 +307,7 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,
|
||||||
len -= cur_len;
|
len -= cur_len;
|
||||||
offset += cur_len;
|
offset += cur_len;
|
||||||
}
|
}
|
||||||
if (csum_size > sizeof(inline_result)) {
|
memset(result, 0, BTRFS_CSUM_SIZE);
|
||||||
result = kzalloc(csum_size, GFP_NOFS);
|
|
||||||
if (!result)
|
|
||||||
return -ENOMEM;
|
|
||||||
} else {
|
|
||||||
result = (char *)&inline_result;
|
|
||||||
}
|
|
||||||
|
|
||||||
btrfs_csum_final(crc, result);
|
btrfs_csum_final(crc, result);
|
||||||
|
|
||||||
|
@ -329,15 +322,12 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,
|
||||||
"%s checksum verify failed on %llu wanted %X found %X level %d",
|
"%s checksum verify failed on %llu wanted %X found %X level %d",
|
||||||
fs_info->sb->s_id, buf->start,
|
fs_info->sb->s_id, buf->start,
|
||||||
val, found, btrfs_header_level(buf));
|
val, found, btrfs_header_level(buf));
|
||||||
if (result != (char *)&inline_result)
|
|
||||||
kfree(result);
|
|
||||||
return -EUCLEAN;
|
return -EUCLEAN;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
write_extent_buffer(buf, result, 0, csum_size);
|
write_extent_buffer(buf, result, 0, csum_size);
|
||||||
}
|
}
|
||||||
if (result != (char *)&inline_result)
|
|
||||||
kfree(result);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue