summaryrefslogtreecommitdiff
path: root/cmds-check.c
diff options
context:
space:
mode:
authorSilvio Fricke <silvio.fricke@gmail.com>2015-09-29 19:10:36 +0200
committerDavid Sterba <dsterba@suse.com>2015-10-21 14:29:26 +0200
commitc47a831cd653fa4ef4979ae7007e60037eddcb37 (patch)
tree69d07646892cda8a71072e8b7920a6afac6ccaec /cmds-check.c
parent9c89f637a3d754ac401b7b6dabe5c7b8c336f848 (diff)
btrfs-progs: use calloc instead of malloc+memset
This patch is generated from a coccinelle semantic patch: identifier t; expression e; statement s; @@ -t = malloc(e); +t = calloc(1, e); ( if (!t) s | if (t == NULL) s | ) -memset(t, 0, e); Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com> [squashed patches into one] Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-check.c')
-rw-r--r--cmds-check.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/cmds-check.c b/cmds-check.c
index 0b14b61e..fe51aae7 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -3020,8 +3020,7 @@ static struct root_backref *get_root_backref(struct root_record *rec,
return backref;
}
- backref = malloc(sizeof(*backref) + namelen + 1);
- memset(backref, 0, sizeof(*backref) + namelen + 1);
+ backref = calloc(1, sizeof(*backref) + namelen + 1);
backref->ref_root = ref_root;
backref->dir = dir;
backref->index = index;
@@ -4892,14 +4891,12 @@ struct chunk_record *btrfs_new_chunk_record(struct extent_buffer *leaf,
ptr = btrfs_item_ptr(leaf, slot, struct btrfs_chunk);
num_stripes = btrfs_chunk_num_stripes(leaf, ptr);
- rec = malloc(btrfs_chunk_record_size(num_stripes));
+ rec = calloc(1, btrfs_chunk_record_size(num_stripes));
if (!rec) {
fprintf(stderr, "memory allocation failed\n");
exit(-1);
}
- memset(rec, 0, btrfs_chunk_record_size(num_stripes));
-
INIT_LIST_HEAD(&rec->list);
INIT_LIST_HEAD(&rec->dextents);
rec->bg_rec = NULL;
@@ -4997,12 +4994,11 @@ btrfs_new_block_group_record(struct extent_buffer *leaf, struct btrfs_key *key,
struct btrfs_block_group_item *ptr;
struct block_group_record *rec;
- rec = malloc(sizeof(*rec));
+ rec = calloc(1, sizeof(*rec));
if (!rec) {
fprintf(stderr, "memory allocation failed\n");
exit(-1);
}
- memset(rec, 0, sizeof(*rec));
rec->cache.start = key->objectid;
rec->cache.size = key->offset;
@@ -5046,12 +5042,11 @@ btrfs_new_device_extent_record(struct extent_buffer *leaf,
struct device_extent_record *rec;
struct btrfs_dev_extent *ptr;
- rec = malloc(sizeof(*rec));
+ rec = calloc(1, sizeof(*rec));
if (!rec) {
fprintf(stderr, "memory allocation failed\n");
exit(-1);
}
- memset(rec, 0, sizeof(*rec));
rec->cache.objectid = key->objectid;
rec->cache.start = key->offset;