diff options
author | Silvio Fricke <silvio.fricke@gmail.com> | 2015-09-29 19:10:36 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2015-10-21 14:29:26 +0200 |
commit | c47a831cd653fa4ef4979ae7007e60037eddcb37 (patch) | |
tree | 69d07646892cda8a71072e8b7920a6afac6ccaec | |
parent | 9c89f637a3d754ac401b7b6dabe5c7b8c336f848 (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>
-rw-r--r-- | btrfs-image.c | 3 | ||||
-rw-r--r-- | btrfs-list.c | 9 | ||||
-rw-r--r-- | chunk-recover.c | 6 | ||||
-rw-r--r-- | cmds-check.c | 13 | ||||
-rw-r--r-- | disk-io.c | 7 | ||||
-rw-r--r-- | extent_io.c | 3 | ||||
-rw-r--r-- | mkfs.c | 3 | ||||
-rw-r--r-- | qgroup.c | 9 | ||||
-rw-r--r-- | quick-test.c | 3 | ||||
-rw-r--r-- | volumes.c | 3 |
10 files changed, 19 insertions, 40 deletions
diff --git a/btrfs-image.c b/btrfs-image.c index 82eed054..20396ef7 100644 --- a/btrfs-image.c +++ b/btrfs-image.c @@ -1505,10 +1505,9 @@ static struct extent_buffer *alloc_dummy_eb(u64 bytenr, u32 size) { struct extent_buffer *eb; - eb = malloc(sizeof(struct extent_buffer) + size); + eb = calloc(1, sizeof(struct extent_buffer) + size); if (!eb) return NULL; - memset(eb, 0, sizeof(struct extent_buffer) + size); eb->start = bytenr; eb->len = size; diff --git a/btrfs-list.c b/btrfs-list.c index d54de61a..7529e11e 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -226,13 +226,12 @@ struct btrfs_list_comparer_set *btrfs_list_alloc_comparer_set(void) size = sizeof(struct btrfs_list_comparer_set) + BTRFS_LIST_NCOMPS_INCREASE * sizeof(struct btrfs_list_comparer); - set = malloc(size); + set = calloc(1, size); if (!set) { fprintf(stderr, "memory allocation failed\n"); exit(1); } - memset(set, 0, size); set->total = BTRFS_LIST_NCOMPS_INCREASE; return set; @@ -474,12 +473,11 @@ static int add_root(struct root_lookup *root_lookup, if (!ret) return 0; - ri = malloc(sizeof(*ri)); + ri = calloc(1, sizeof(*ri)); if (!ri) { printf("memory allocation failed\n"); exit(1); } - memset(ri, 0, sizeof(*ri)); ri->root_id = root_id; if (name && name_len > 0) { @@ -1208,13 +1206,12 @@ struct btrfs_list_filter_set *btrfs_list_alloc_filter_set(void) size = sizeof(struct btrfs_list_filter_set) + BTRFS_LIST_NFILTERS_INCREASE * sizeof(struct btrfs_list_filter); - set = malloc(size); + set = calloc(1, size); if (!set) { fprintf(stderr, "memory allocation failed\n"); exit(1); } - memset(set, 0, size); set->total = BTRFS_LIST_NFILTERS_INCREASE; return set; diff --git a/chunk-recover.c b/chunk-recover.c index 1fb04f77..d0ca920f 100644 --- a/chunk-recover.c +++ b/chunk-recover.c @@ -85,13 +85,12 @@ static struct extent_record *btrfs_new_extent_record(struct extent_buffer *eb) { struct extent_record *rec; - rec = malloc(sizeof(*rec)); + rec = calloc(1, sizeof(*rec)); if (!rec) { fprintf(stderr, "Fail to allocate memory for extent record.\n"); exit(1); } - memset(rec, 0, sizeof(*rec)); rec->cache.start = btrfs_header_bytenr(eb); rec->cache.size = eb->len; rec->generation = btrfs_header_generation(eb); @@ -2228,10 +2227,9 @@ static int btrfs_recover_chunks(struct recover_control *rc) nstripes = btrfs_get_device_extents(bg->objectid, &rc->devext.no_chunk_orphans, &devexts); - chunk = malloc(btrfs_chunk_record_size(nstripes)); + chunk = calloc(1, btrfs_chunk_record_size(nstripes)); if (!chunk) return -ENOMEM; - memset(chunk, 0, btrfs_chunk_record_size(nstripes)); INIT_LIST_HEAD(&chunk->dextents); chunk->bg_rec = bg; chunk->cache.start = bg->objectid; 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; @@ -698,10 +698,9 @@ struct btrfs_root *btrfs_read_fs_root_no_cache(struct btrfs_fs_info *fs_info, u32 blocksize; int ret = 0; - root = malloc(sizeof(*root)); + root = calloc(1, sizeof(*root)); if (!root) return ERR_PTR(-ENOMEM); - memset(root, 0, sizeof(*root)); if (location->offset == (u64)-1) { ret = find_and_setup_root(tree_root, fs_info, location->objectid, root); @@ -829,12 +828,10 @@ struct btrfs_fs_info *btrfs_new_fs_info(int writable, u64 sb_bytenr) { struct btrfs_fs_info *fs_info; - fs_info = malloc(sizeof(struct btrfs_fs_info)); + fs_info = calloc(1, sizeof(struct btrfs_fs_info)); if (!fs_info) return NULL; - memset(fs_info, 0, sizeof(struct btrfs_fs_info)); - fs_info->tree_root = calloc(1, sizeof(struct btrfs_root)); fs_info->extent_root = calloc(1, sizeof(struct btrfs_root)); fs_info->chunk_root = calloc(1, sizeof(struct btrfs_root)); diff --git a/extent_io.c b/extent_io.c index 07695ef8..75496ce9 100644 --- a/extent_io.c +++ b/extent_io.c @@ -538,12 +538,11 @@ static struct extent_buffer *__alloc_extent_buffer(struct extent_io_tree *tree, { struct extent_buffer *eb; - eb = malloc(sizeof(struct extent_buffer) + blocksize); + eb = calloc(1, sizeof(struct extent_buffer) + blocksize); if (!eb) { BUG(); return NULL; } - memset(eb, 0, sizeof(struct extent_buffer) + blocksize); eb->start = bytenr; eb->len = blocksize; @@ -668,12 +668,11 @@ static int add_file_items(struct btrfs_trans_handle *trans, * do our IO in extent buffers so it can work * against any raid type */ - eb = malloc(sizeof(*eb) + sectorsize); + eb = calloc(1, sizeof(*eb) + sectorsize); if (!eb) { ret = -ENOMEM; goto end; } - memset(eb, 0, sizeof(*eb) + sectorsize); again: @@ -436,13 +436,12 @@ struct btrfs_qgroup_comparer_set *btrfs_qgroup_alloc_comparer_set(void) size = sizeof(struct btrfs_qgroup_comparer_set) + BTRFS_QGROUP_NCOMPS_INCREASE * sizeof(struct btrfs_qgroup_comparer); - set = malloc(size); + set = calloc(1, size); if (!set) { fprintf(stderr, "memory allocation failed\n"); exit(1); } - memset(set, 0, size); set->total = BTRFS_QGROUP_NCOMPS_INCREASE; return set; @@ -644,12 +643,11 @@ static int add_qgroup(struct qgroup_lookup *qgroup_lookup, u64 qgroupid, if (!ret) return 0; - bq = malloc(sizeof(*bq)); + bq = calloc(1, sizeof(*bq)); if (!bq) { printf("memory allocation failed\n"); exit(1); } - memset(bq, 0, sizeof(*bq)); if (qgroupid) { bq->qgroupid = qgroupid; INIT_LIST_HEAD(&bq->qgroups); @@ -813,12 +811,11 @@ struct btrfs_qgroup_filter_set *btrfs_qgroup_alloc_filter_set(void) size = sizeof(struct btrfs_qgroup_filter_set) + BTRFS_QGROUP_NFILTERS_INCREASE * sizeof(struct btrfs_qgroup_filter); - set = malloc(size); + set = calloc(1, size); if (!set) { fprintf(stderr, "memory allocation failed\n"); exit(1); } - memset(set, 0, size); set->total = BTRFS_QGROUP_NFILTERS_INCREASE; return set; diff --git a/quick-test.c b/quick-test.c index 5dfb2feb..ffde85d9 100644 --- a/quick-test.c +++ b/quick-test.c @@ -46,8 +46,7 @@ int main(int ac, char **av) { struct btrfs_root *root; struct btrfs_trans_handle *trans; - buf = malloc(512); - memset(buf, 0, 512); + buf = calloc(1, 512); radix_tree_init(); @@ -1968,10 +1968,9 @@ static void split_eb_for_raid56(struct btrfs_fs_info *info, if (raid_map[i] >= BTRFS_RAID5_P_STRIPE) break; - eb = malloc(sizeof(struct extent_buffer) + stripe_len); + eb = calloc(1, sizeof(struct extent_buffer) + stripe_len); if (!eb) BUG(); - memset(eb, 0, sizeof(struct extent_buffer) + stripe_len); eb->start = raid_map[i]; eb->len = stripe_len; |