Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Lin Ming <mlin@kernel.org>
To: linux-btrfs@vger.kernel.org
Cc: Eric Sandeen <sandeen@redhat.com>
Subject: [PATCH] btrfs-progs: pass up return value of walk_down_tree
Date: Thu,  2 May 2013 23:51:38 -0400	[thread overview]
Message-ID: <1367553098-6315-1-git-send-email-mlin@kernel.org> (raw)

Pass up return value of walk_down_tree, so the caller can handle it.
This also fixes a segfault when read_tree_block fails with NULL returned.

Signed-off-by: Lin Ming <mlin@kernel.org>
---
 cmds-check.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 12192fa..7a51627 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -1201,7 +1201,7 @@ static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
 	struct extent_buffer *next;
 	struct extent_buffer *cur;
 	u32 blocksize;
-	int ret;
+	int ret, err = 0;
 	u64 refs;
 
 	WARN_ON(*level < 0);
@@ -1209,14 +1209,18 @@ static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
 	ret = btrfs_lookup_extent_info(NULL, root,
 				       path->nodes[*level]->start,
 				       path->nodes[*level]->len, &refs, NULL);
-	if (ret < 0)
+	if (ret < 0) {
+		err = ret;
 		goto out;
+	}
 
 	if (refs > 1) {
 		ret = enter_shared_node(root, path->nodes[*level]->start,
 					refs, wc, *level);
-		if (ret > 0)
+		if (ret > 0) {
+			err = ret;
 			goto out;
+		}
 	}
 
 	while (*level >= 0) {
@@ -1256,6 +1260,10 @@ static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
 			reada_walk_down(root, cur, path->slots[*level]);
 			next = read_tree_block(root, bytenr, blocksize,
 					       ptr_gen);
+			if (!next) {
+				err = -EIO;
+				goto out;
+			}
 		}
 
 		*level = *level - 1;
@@ -1265,7 +1273,7 @@ static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
 	}
 out:
 	path->slots[*level] = btrfs_header_nritems(path->nodes[*level]);
-	return 0;
+	return err;
 }
 
 static int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path,
-- 
1.7.2.5


                 reply	other threads:[~2013-05-02 15:51 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=1367553098-6315-1-git-send-email-mlin@kernel.org \
    --to=mlin@kernel.org \
    --cc=linux-btrfs@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox