public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: zhanchengbin <zhanchengbin1@huawei.com>
To: <sandeen@sandeen.net>, <djwong@kernel.org>
Cc: <liuzhiqiang26@huawei.com>, linfeilong <linfeilong@huawei.com>,
	<linux-xfs@vger.kernel.org>
Subject: [PATCH 2/3] db: avoid to use NULL pointer
Date: Mon, 6 Jun 2022 20:33:39 +0800	[thread overview]
Message-ID: <534c6d3c-4bd1-c07d-d927-3715eb8c19b2@huawei.com> (raw)
In-Reply-To: <7f4abf2a-5ea5-e2ee-786e-88d871d29475@huawei.com>

Changed malloc to xmalloc.

Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
---
  db/block.c | 2 +-
  db/check.c | 4 ++--
  db/faddr.c | 6 +++---
  db/namei.c | 2 +-
  4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/db/block.c b/db/block.c
index f31f9544..349cf6ec 100644
--- a/db/block.c
+++ b/db/block.c
@@ -180,7 +180,7 @@ dblock_f(
  		return 0;
  	}
  	nex = nb = type == TYP_DIR2 ? mp->m_dir_geo->fsbcount : 1;
-	bmp = malloc(nb * sizeof(*bmp));
+	bmp = xmalloc(nb * sizeof(*bmp));
  	bmap(bno, nb, XFS_DATA_FORK, &nex, bmp);
  	if (nex == 0) {
  		dbprintf(_("file data block is unmapped\n"));
diff --git a/db/check.c b/db/check.c
index a9c6e632..cc3c7832 100644
--- a/db/check.c
+++ b/db/check.c
@@ -1782,7 +1782,7 @@ dir_hash_add(
  	dirhash_t		*p;

  	i = DIR_HASH_FUNC(hash, addr);
-	p = malloc(sizeof(*p));
+	p = xmalloc(sizeof(*p));
  	p->next = dirhash[i];
  	dirhash[i] = p;
  	p->hashval = hash;
@@ -3094,7 +3094,7 @@ process_leaf_node_dir_v2(
  	v2 = verbose || id->ilist;
  	v = parent = 0;
  	dbno = NULLFILEOFF;
-	freetab = malloc(FREETAB_SIZE(dirsize / mp->m_dir_geo->blksize));
+	freetab = xmalloc(FREETAB_SIZE(dirsize / mp->m_dir_geo->blksize));
  	freetab->naents = (int)(dirsize / mp->m_dir_geo->blksize);
  	freetab->nents = 0;
  	for (i = 0; i < freetab->naents; i++)
diff --git a/db/faddr.c b/db/faddr.c
index 0127c5d1..cc21faaf 100644
--- a/db/faddr.c
+++ b/db/faddr.c
@@ -137,7 +137,7 @@ fa_cfileoffd(
  		return;
  	}
  	nex = nb = next == TYP_DIR2 ? mp->m_dir_geo->fsbcount : 1;
-	bmp = malloc(nb * sizeof(*bmp));
+	bmp = xmalloc(nb * sizeof(*bmp));
  	bmap(bno, nb, XFS_DATA_FORK, &nex, bmp);
  	if (nex == 0) {
  		dbprintf(_("file block is unmapped\n"));
@@ -221,7 +221,7 @@ fa_dfiloffd(
  		return;
  	}
  	nex = nb = next == TYP_DIR2 ? mp->m_dir_geo->fsbcount : 1;
-	bmp = malloc(nb * sizeof(*bmp));
+	bmp = xmalloc(nb * sizeof(*bmp));
  	bmap(bno, nb, XFS_DATA_FORK, &nex, bmp);
  	if (nex == 0) {
  		dbprintf(_("file block is unmapped\n"));
@@ -274,7 +274,7 @@ fa_dirblock(
  		return;
  	}
  	nex = mp->m_dir_geo->fsbcount;
-	bmp = malloc(nex * sizeof(*bmp));
+	bmp = xmalloc(nex * sizeof(*bmp));
  	bmap(bno, mp->m_dir_geo->fsbcount, XFS_DATA_FORK, &nex, bmp);
  	if (nex == 0) {
  		dbprintf(_("directory block is unmapped\n"));
diff --git a/db/namei.c b/db/namei.c
index e44667a9..d1a9904b 100644
--- a/db/namei.c
+++ b/db/namei.c
@@ -266,7 +266,7 @@ dir_emit(
  		 * copy the string to a buffer so that we can add the null
  		 * terminator.
  		 */
-		display_name = malloc(namelen + 1);
+		display_name = xmalloc(namelen + 1);
  		memcpy(display_name, name, namelen);
  		display_name[namelen] = 0;
  		xname.len = namelen;
-- 
2.27.0


  parent reply	other threads:[~2022-06-06 12:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-06 12:31 [PATCH 0/3] xfsprogs: avoid to use NULL pointer zhanchengbin
2022-06-06 12:33 ` [PATCH 1/3] mkfs/proto.c: " zhanchengbin
2022-06-06 14:29   ` Eric Sandeen
2022-06-06 21:46     ` Dave Chinner
2022-06-06 12:33 ` zhanchengbin [this message]
2022-06-06 12:34 ` [PATCH 3/3] repair/slab.c: " zhanchengbin

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=534c6d3c-4bd1-c07d-d927-3715eb8c19b2@huawei.com \
    --to=zhanchengbin1@huawei.com \
    --cc=djwong@kernel.org \
    --cc=linfeilong@huawei.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=liuzhiqiang26@huawei.com \
    --cc=sandeen@sandeen.net \
    /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