summaryrefslogtreecommitdiff
path: root/disk-io.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2015-11-06 17:50:48 +0100
committerDavid Sterba <dsterba@suse.com>2015-11-13 18:24:34 +0100
commit59a90681616ba97437b8053b1917fa72f0162e4c (patch)
treea57e5a64603340e88bca892e2c166f45860be541 /disk-io.c
parentd7492ec59e2b0a7aa039aad8d77f9d0d701eac65 (diff)
btrfs-progs: use on-stack buffer in __csum_tree_block_size
We know the maximum size of a checksum, calling malloc for 4 bytes is weird. Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'disk-io.c')
-rw-r--r--disk-io.c8
1 files changed, 1 insertions, 7 deletions
diff --git a/disk-io.c b/disk-io.c
index 139bc80f..7a63b91d 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -126,14 +126,10 @@ void btrfs_csum_final(u32 crc, char *result)
static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
int verify, int silent)
{
- char *result;
+ char result[BTRFS_CSUM_SIZE];
u32 len;
u32 crc = ~(u32)0;
- result = malloc(csum_size * sizeof(char));
- if (!result)
- return 1;
-
len = buf->len - BTRFS_CSUM_SIZE;
crc = crc32c(crc, buf->data + BTRFS_CSUM_SIZE, len);
btrfs_csum_final(crc, result);
@@ -145,13 +141,11 @@ static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
(unsigned long long)buf->start,
*((u32 *)result),
*((u32*)(char *)buf->data));
- free(result);
return 1;
}
} else {
write_extent_buffer(buf, result, 0, csum_size);
}
- free(result);
return 0;
}