All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: xfs <linux-xfs@vger.kernel.org>
Subject: [PATCH] xfs_repair: change null check to assertion
Date: Tue, 20 Dec 2016 19:09:45 -0800	[thread overview]
Message-ID: <20161221030945.GD5487@birch.djwong.org> (raw)

It /should/ be the case that we never run out of records
before we run out of btree blocks, so change the null check
(that was only to appease Coverity) to an assert.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 repair/phase5.c |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/repair/phase5.c b/repair/phase5.c
index cbda556..ebe1f7d 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -1579,6 +1579,7 @@ build_rmap_tree(
 	struct xfs_rmap_irec	highest_key = {0};
 	struct xfs_rmap_irec	hi_key = {0};
 	struct bt_stat_level	*lptr;
+	int			numrecs;
 	int			level = btree_curs->num_levels;
 	int			error;
 
@@ -1622,7 +1623,10 @@ _("Insufficient memory to construct reverse-map cursor."));
 	rm_rec = pop_slab_cursor(rmap_cur);
 	lptr = &btree_curs->level[0];
 
-	for (i = 0; i < lptr->num_blocks && rm_rec != NULL; i++)  {
+	for (i = 0; i < lptr->num_blocks; i++)  {
+		numrecs = lptr->num_recs_pb + (lptr->modulo > 0);
+		ASSERT(rm_rec != NULL || numrecs == 0);
+
 		/*
 		 * block initialization, lay in block header
 		 */
@@ -1634,8 +1638,7 @@ _("Insufficient memory to construct reverse-map cursor."));
 					XFS_BTREE_CRC_BLOCKS);
 
 		bt_hdr->bb_u.s.bb_leftsib = cpu_to_be32(lptr->prev_agbno);
-		bt_hdr->bb_numrecs = cpu_to_be16(lptr->num_recs_pb +
-							(lptr->modulo > 0));
+		bt_hdr->bb_numrecs = cpu_to_be16(numrecs);
 
 		if (lptr->modulo > 0)
 			lptr->modulo--;
@@ -1883,6 +1886,7 @@ build_refcount_tree(
 	struct xfs_slab_cursor	*refc_cur;
 	struct xfs_refcount_rec	*bt_rec;
 	struct bt_stat_level	*lptr;
+	int			numrecs;
 	int			level = btree_curs->num_levels;
 	int			error;
 
@@ -1925,7 +1929,10 @@ _("Insufficient memory to construct refcount cursor."));
 	refc_rec = pop_slab_cursor(refc_cur);
 	lptr = &btree_curs->level[0];
 
-	for (i = 0; i < lptr->num_blocks && refc_rec != NULL; i++)  {
+	for (i = 0; i < lptr->num_blocks; i++)  {
+		numrecs = lptr->num_recs_pb + (lptr->modulo > 0);
+		ASSERT(refc_rec != NULL || numrecs == 0);
+
 		/*
 		 * block initialization, lay in block header
 		 */
@@ -1937,8 +1944,7 @@ _("Insufficient memory to construct refcount cursor."));
 					XFS_BTREE_CRC_BLOCKS);
 
 		bt_hdr->bb_u.s.bb_leftsib = cpu_to_be32(lptr->prev_agbno);
-		bt_hdr->bb_numrecs = cpu_to_be16(lptr->num_recs_pb +
-							(lptr->modulo > 0));
+		bt_hdr->bb_numrecs = cpu_to_be16(numrecs);
 
 		if (lptr->modulo > 0)
 			lptr->modulo--;

                 reply	other threads:[~2016-12-21  3:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20161221030945.GD5487@birch.djwong.org \
    --to=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.