linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] using of calloc instead of malloc+memset
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
@ 2015-09-29 17:10 ` Silvio Fricke
  2015-09-30 16:48   ` David Sterba
  2015-09-30 16:54   ` David Sterba
  2015-09-29 17:10 ` [PATCH 01/11] btrfs-progs: use calloc instead of malloc+memset for btrfs-image.c Silvio Fricke
                   ` (10 subsequent siblings)
  11 siblings, 2 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

Hi btrfs,

please review my patches about switching from malloc with memset to calloc.
Thanks for that and eventual inclusion of my patches.

Silvio

Silvio Fricke (11):
  btrfs-progs: use calloc instead of malloc+memset for btrfs-image.c
  btrfs-progs: use calloc instead of malloc+memset for btrfs-list.c
  btrfs-progs: use calloc instead of malloc+memset for chunk-recover.c
  btrfs-progs: use calloc instead of malloc+memset for cmds-check.c
  btrfs-progs: use calloc instead of malloc+memset for disk-io.c
  btrfs-progs: use calloc instead of malloc+memset for extent_io.c
  btrfs-progs: use calloc instead of malloc+memset for mkfs.c
  btrfs-progs: use calloc instead of malloc+memset for qgroup.c
  btrfs-progs: use calloc instead of malloc+memset for quick-test.c
  btrfs-progs: use calloc instead of malloc+memset for volumes.c
  btrfs-progs: check: fix memset range

 btrfs-image.c   |  3 +--
 btrfs-list.c    |  9 +++------
 chunk-recover.c |  6 ++----
 cmds-check.c    | 12 ++++--------
 disk-io.c       |  7 ++-----
 extent_io.c     |  3 +--
 mkfs.c          |  3 +--
 qgroup.c        |  9 +++------
 quick-test.c    |  3 +--
 volumes.c       |  3 +--
 10 files changed, 19 insertions(+), 39 deletions(-)

-- 
2.5.3


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 01/11] btrfs-progs: use calloc instead of malloc+memset for btrfs-image.c
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
  2015-09-29 17:10 ` [PATCH 00/11] using of calloc instead of malloc+memset Silvio Fricke
@ 2015-09-29 17:10 ` Silvio Fricke
  2015-09-29 17:10 ` [PATCH 02/11] btrfs-progs: use calloc instead of malloc+memset for btrfs-list.c Silvio Fricke
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

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>
---
 btrfs-image.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/btrfs-image.c b/btrfs-image.c
index 82eed05..20396ef 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;
-- 
2.5.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 02/11] btrfs-progs: use calloc instead of malloc+memset for btrfs-list.c
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
  2015-09-29 17:10 ` [PATCH 00/11] using of calloc instead of malloc+memset Silvio Fricke
  2015-09-29 17:10 ` [PATCH 01/11] btrfs-progs: use calloc instead of malloc+memset for btrfs-image.c Silvio Fricke
@ 2015-09-29 17:10 ` Silvio Fricke
  2015-09-29 17:10 ` [PATCH 03/11] btrfs-progs: use calloc instead of malloc+memset for chunk-recover.c Silvio Fricke
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

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>
---
 btrfs-list.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/btrfs-list.c b/btrfs-list.c
index d54de61..7529e11 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;
-- 
2.5.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 03/11] btrfs-progs: use calloc instead of malloc+memset for chunk-recover.c
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
                   ` (2 preceding siblings ...)
  2015-09-29 17:10 ` [PATCH 02/11] btrfs-progs: use calloc instead of malloc+memset for btrfs-list.c Silvio Fricke
@ 2015-09-29 17:10 ` Silvio Fricke
  2015-09-29 17:10 ` [PATCH 04/11] btrfs-progs: use calloc instead of malloc+memset for cmds-check.c Silvio Fricke
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

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>
---
 chunk-recover.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/chunk-recover.c b/chunk-recover.c
index 1fb04f7..d0ca920 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;
-- 
2.5.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 04/11] btrfs-progs: use calloc instead of malloc+memset for cmds-check.c
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
                   ` (3 preceding siblings ...)
  2015-09-29 17:10 ` [PATCH 03/11] btrfs-progs: use calloc instead of malloc+memset for chunk-recover.c Silvio Fricke
@ 2015-09-29 17:10 ` Silvio Fricke
  2015-09-29 17:10 ` [PATCH 05/11] btrfs-progs: use calloc instead of malloc+memset for disk-io.c Silvio Fricke
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

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>
---
 cmds-check.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 07df79f..2923d05 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4892,14 +4892,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 +4995,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 +5043,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;
-- 
2.5.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 05/11] btrfs-progs: use calloc instead of malloc+memset for disk-io.c
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
                   ` (4 preceding siblings ...)
  2015-09-29 17:10 ` [PATCH 04/11] btrfs-progs: use calloc instead of malloc+memset for cmds-check.c Silvio Fricke
@ 2015-09-29 17:10 ` Silvio Fricke
  2015-09-29 17:10 ` [PATCH 06/11] btrfs-progs: use calloc instead of malloc+memset for extent_io.c Silvio Fricke
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

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>
---
 disk-io.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/disk-io.c b/disk-io.c
index 2469a84..f7e6c41 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -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));
-- 
2.5.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 06/11] btrfs-progs: use calloc instead of malloc+memset for extent_io.c
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
                   ` (5 preceding siblings ...)
  2015-09-29 17:10 ` [PATCH 05/11] btrfs-progs: use calloc instead of malloc+memset for disk-io.c Silvio Fricke
@ 2015-09-29 17:10 ` Silvio Fricke
  2015-09-29 17:10 ` [PATCH 07/11] btrfs-progs: use calloc instead of malloc+memset for mkfs.c Silvio Fricke
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

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>
---
 extent_io.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/extent_io.c b/extent_io.c
index 07695ef..75496ce 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;
-- 
2.5.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 07/11] btrfs-progs: use calloc instead of malloc+memset for mkfs.c
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
                   ` (6 preceding siblings ...)
  2015-09-29 17:10 ` [PATCH 06/11] btrfs-progs: use calloc instead of malloc+memset for extent_io.c Silvio Fricke
@ 2015-09-29 17:10 ` Silvio Fricke
  2015-09-29 17:10 ` [PATCH 08/11] btrfs-progs: use calloc instead of malloc+memset for qgroup.c Silvio Fricke
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

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>
---
 mkfs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mkfs.c b/mkfs.c
index a5802f7..ecd6fbf 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -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:
 
-- 
2.5.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 08/11] btrfs-progs: use calloc instead of malloc+memset for qgroup.c
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
                   ` (7 preceding siblings ...)
  2015-09-29 17:10 ` [PATCH 07/11] btrfs-progs: use calloc instead of malloc+memset for mkfs.c Silvio Fricke
@ 2015-09-29 17:10 ` Silvio Fricke
  2015-09-29 17:10 ` [PATCH 09/11] btrfs-progs: use calloc instead of malloc+memset for quick-test.c Silvio Fricke
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

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>
---
 qgroup.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/qgroup.c b/qgroup.c
index ec9a3ac..99fddea 100644
--- a/qgroup.c
+++ b/qgroup.c
@@ -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;
-- 
2.5.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 09/11] btrfs-progs: use calloc instead of malloc+memset for quick-test.c
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
                   ` (8 preceding siblings ...)
  2015-09-29 17:10 ` [PATCH 08/11] btrfs-progs: use calloc instead of malloc+memset for qgroup.c Silvio Fricke
@ 2015-09-29 17:10 ` Silvio Fricke
  2015-09-29 17:10 ` [PATCH 10/11] btrfs-progs: use calloc instead of malloc+memset for volumes.c Silvio Fricke
  2015-09-29 17:10 ` [PATCH 11/11] btrfs-progs: check: fix memset range Silvio Fricke
  11 siblings, 0 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

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>
---
 quick-test.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/quick-test.c b/quick-test.c
index 5dfb2fe..ffde85d 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();
 
-- 
2.5.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 10/11] btrfs-progs: use calloc instead of malloc+memset for volumes.c
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
                   ` (9 preceding siblings ...)
  2015-09-29 17:10 ` [PATCH 09/11] btrfs-progs: use calloc instead of malloc+memset for quick-test.c Silvio Fricke
@ 2015-09-29 17:10 ` Silvio Fricke
  2015-09-29 17:10 ` [PATCH 11/11] btrfs-progs: check: fix memset range Silvio Fricke
  11 siblings, 0 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

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>
---
 volumes.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/volumes.c b/volumes.c
index ca50f1c..83ddd16 100644
--- a/volumes.c
+++ b/volumes.c
@@ -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;
-- 
2.5.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 11/11] btrfs-progs: check: fix memset range
       [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
                   ` (10 preceding siblings ...)
  2015-09-29 17:10 ` [PATCH 10/11] btrfs-progs: use calloc instead of malloc+memset for volumes.c Silvio Fricke
@ 2015-09-29 17:10 ` Silvio Fricke
  11 siblings, 0 replies; 14+ messages in thread
From: Silvio Fricke @ 2015-09-29 17:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Silvio Fricke

Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com>
---
 cmds-check.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmds-check.c b/cmds-check.c
index 2923d05..2c32ff3 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -3021,7 +3021,7 @@ static struct root_backref *get_root_backref(struct root_record *rec,
 	}
 
 	backref = malloc(sizeof(*backref) + namelen + 1);
-	memset(backref, 0, sizeof(*backref));
+	memset(backref, 0, sizeof(*backref) + namelen + 1);
 	backref->ref_root = ref_root;
 	backref->dir = dir;
 	backref->index = index;
-- 
2.5.3


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 00/11] using of calloc instead of malloc+memset
  2015-09-29 17:10 ` [PATCH 00/11] using of calloc instead of malloc+memset Silvio Fricke
@ 2015-09-30 16:48   ` David Sterba
  2015-09-30 16:54   ` David Sterba
  1 sibling, 0 replies; 14+ messages in thread
From: David Sterba @ 2015-09-30 16:48 UTC (permalink / raw)
  To: Silvio Fricke; +Cc: linux-btrfs

On Tue, Sep 29, 2015 at 07:10:35PM +0200, Silvio Fricke wrote:
> Silvio Fricke (11):
>   btrfs-progs: use calloc instead of malloc+memset for btrfs-image.c
>   btrfs-progs: use calloc instead of malloc+memset for btrfs-list.c
>   btrfs-progs: use calloc instead of malloc+memset for chunk-recover.c
>   btrfs-progs: use calloc instead of malloc+memset for cmds-check.c
>   btrfs-progs: use calloc instead of malloc+memset for disk-io.c
>   btrfs-progs: use calloc instead of malloc+memset for extent_io.c
>   btrfs-progs: use calloc instead of malloc+memset for mkfs.c
>   btrfs-progs: use calloc instead of malloc+memset for qgroup.c
>   btrfs-progs: use calloc instead of malloc+memset for quick-test.c
>   btrfs-progs: use calloc instead of malloc+memset for volumes.c

Thanks.

I think that all of these can be squeezed into one, the change
is logically same in all the files and easy to review even in a big
patch. So I'll do that, the lat patch will be separate as it's a fix.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 00/11] using of calloc instead of malloc+memset
  2015-09-29 17:10 ` [PATCH 00/11] using of calloc instead of malloc+memset Silvio Fricke
  2015-09-30 16:48   ` David Sterba
@ 2015-09-30 16:54   ` David Sterba
  1 sibling, 0 replies; 14+ messages in thread
From: David Sterba @ 2015-09-30 16:54 UTC (permalink / raw)
  To: Silvio Fricke; +Cc: linux-btrfs

On Tue, Sep 29, 2015 at 07:10:35PM +0200, Silvio Fricke wrote:
> Silvio Fricke (11):
>   btrfs-progs: use calloc instead of malloc+memset for btrfs-image.c
>   btrfs-progs: use calloc instead of malloc+memset for btrfs-list.c
>   btrfs-progs: use calloc instead of malloc+memset for chunk-recover.c
>   btrfs-progs: use calloc instead of malloc+memset for cmds-check.c
>   btrfs-progs: use calloc instead of malloc+memset for disk-io.c
>   btrfs-progs: use calloc instead of malloc+memset for extent_io.c
>   btrfs-progs: use calloc instead of malloc+memset for mkfs.c
>   btrfs-progs: use calloc instead of malloc+memset for qgroup.c
>   btrfs-progs: use calloc instead of malloc+memset for quick-test.c
>   btrfs-progs: use calloc instead of malloc+memset for volumes.c
>   btrfs-progs: check: fix memset range

Actually this patch should go first (reordered in git now), then the
semantic rule would apply to it as well and now the malloc/memset patter
is gone.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-09-30 16:55 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1443459879.git.silvio.fricke@gmail.com>
2015-09-29 17:10 ` [PATCH 00/11] using of calloc instead of malloc+memset Silvio Fricke
2015-09-30 16:48   ` David Sterba
2015-09-30 16:54   ` David Sterba
2015-09-29 17:10 ` [PATCH 01/11] btrfs-progs: use calloc instead of malloc+memset for btrfs-image.c Silvio Fricke
2015-09-29 17:10 ` [PATCH 02/11] btrfs-progs: use calloc instead of malloc+memset for btrfs-list.c Silvio Fricke
2015-09-29 17:10 ` [PATCH 03/11] btrfs-progs: use calloc instead of malloc+memset for chunk-recover.c Silvio Fricke
2015-09-29 17:10 ` [PATCH 04/11] btrfs-progs: use calloc instead of malloc+memset for cmds-check.c Silvio Fricke
2015-09-29 17:10 ` [PATCH 05/11] btrfs-progs: use calloc instead of malloc+memset for disk-io.c Silvio Fricke
2015-09-29 17:10 ` [PATCH 06/11] btrfs-progs: use calloc instead of malloc+memset for extent_io.c Silvio Fricke
2015-09-29 17:10 ` [PATCH 07/11] btrfs-progs: use calloc instead of malloc+memset for mkfs.c Silvio Fricke
2015-09-29 17:10 ` [PATCH 08/11] btrfs-progs: use calloc instead of malloc+memset for qgroup.c Silvio Fricke
2015-09-29 17:10 ` [PATCH 09/11] btrfs-progs: use calloc instead of malloc+memset for quick-test.c Silvio Fricke
2015-09-29 17:10 ` [PATCH 10/11] btrfs-progs: use calloc instead of malloc+memset for volumes.c Silvio Fricke
2015-09-29 17:10 ` [PATCH 11/11] btrfs-progs: check: fix memset range Silvio Fricke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).