linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Silvio Fricke <silvio.fricke@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Silvio Fricke <silvio.fricke@gmail.com>
Subject: [PATCH 04/11] btrfs-progs: use calloc instead of malloc+memset for cmds-check.c
Date: Tue, 29 Sep 2015 19:10:39 +0200	[thread overview]
Message-ID: <9f98533d94e0228c499935656d24904fa4877999.1443546001.git.silvio.fricke@gmail.com> (raw)
In-Reply-To: <cover.1443546000.git.silvio.fricke@gmail.com>
In-Reply-To: <cover.1443546000.git.silvio.fricke@gmail.com>

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


  parent reply	other threads:[~2015-09-29 17:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 ` Silvio Fricke [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9f98533d94e0228c499935656d24904fa4877999.1443546001.git.silvio.fricke@gmail.com \
    --to=silvio.fricke@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).