Btrfs: more return code checking

Signed-off-by: Chris Mason <chris.mason@oracle.com>
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index be2be02..2732399 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1087,7 +1087,9 @@
 			break;
 		}
 		level++;
-		free_extent(root, blocknr, 1);
+		wret = free_extent(root, blocknr, 1);
+		if (wret)
+			ret = wret;
 		if (!path->nodes[level])
 			BUG();
 	}
@@ -1136,7 +1138,9 @@
 			wret = del_ptr(root, path, 1);
 			if (wret)
 				ret = wret;
-			free_extent(root, leaf_buf->blocknr, 1);
+			wret = free_extent(root, leaf_buf->blocknr, 1);
+			if (wret)
+				ret = wret;
 		}
 	} else {
 		int used = leaf_space_used(leaf, 0, leaf->header.nritems);
@@ -1173,7 +1177,9 @@
 				if (wret)
 					ret = wret;
 				tree_block_release(root, leaf_buf);
-				free_extent(root, blocknr, 1);
+				wret = free_extent(root, blocknr, 1);
+				if (wret)
+					ret = wret;
 			} else {
 				tree_block_release(root, leaf_buf);
 			}
@@ -1184,7 +1190,8 @@
 
 /*
  * walk up the tree as far as required to find the next leaf.
- * returns 0 if it found something or -1 if there are no greater leaves.
+ * returns 0 if it found something or 1 if there are no greater leaves.
+ * returns < 0 on io errors.
  */
 int next_leaf(struct ctree_root *root, struct ctree_path *path)
 {
@@ -1196,7 +1203,7 @@
 
 	while(level < MAX_LEVEL) {
 		if (!path->nodes[level])
-			return -1;
+			return 1;
 		slot = path->slots[level] + 1;
 		c = path->nodes[level];
 		if (slot >= c->node.header.nritems) {
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 97715ba..074f4b1 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -105,8 +105,8 @@
  * ins->offset == number of blocks
  * Any available blocks before search_start are skipped.
  */
-int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
-		     u64 search_start, u64 search_end, struct key *ins)
+static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
+			    u64 search_start, u64 search_end, struct key *ins)
 {
 	struct ctree_path path;
 	struct key *key;
@@ -125,10 +125,8 @@
 	ins->flags = 0;
 	start_found = 0;
 	ret = search_slot(root, ins, &path, 0);
-	if (ret < 0) {
-		release_path(root, &path);
-		return ret;
-	}
+	if (ret < 0)
+		goto error;
 
 	while (1) {
 		l = &path.nodes[0]->leaf;
@@ -137,6 +135,8 @@
 			ret = next_leaf(root, &path);
 			if (ret == 0)
 				continue;
+			if (ret < 0)
+				goto error;
 			if (!start_found) {
 				ins->objectid = search_start;
 				ins->offset = num_blocks;
@@ -187,6 +187,9 @@
 	if (ins->offset != 1)
 		BUG();
 	return 0;
+error:
+	release_path(root, &path);
+	return ret;
 }
 
 /*