btrfs-progs: handle ulist_add errors in qgroup-verify

Resolves-coverity-id: 1364084
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2016-07-15 16:12:00 +02:00
parent addd7e7f20
commit 048f6274ff
1 changed files with 18 additions and 5 deletions

View File

@ -318,10 +318,11 @@ FREE_RB_BASED_TREE(ref, free_ref_node);
/* /*
* Resolves all the possible roots for the ref at parent. * Resolves all the possible roots for the ref at parent.
*/ */
static void find_parent_roots(struct ulist *roots, u64 parent) static int find_parent_roots(struct ulist *roots, u64 parent)
{ {
struct ref *ref; struct ref *ref;
struct rb_node *node; struct rb_node *node;
int ret;
/* /*
* Search the rbtree for the first ref with bytenr == parent. * Search the rbtree for the first ref with bytenr == parent.
@ -348,16 +349,25 @@ static void find_parent_roots(struct ulist *roots, u64 parent)
do { do {
if (ref->root) { if (ref->root) {
if (is_fstree(ref->root)) if (is_fstree(ref->root)) {
ulist_add(roots, ref->root, 0, 0); ret = ulist_add(roots, ref->root, 0, 0);
if (ret < 0)
goto out;
}
} else { } else {
find_parent_roots(roots, ref->parent); ret = find_parent_roots(roots, ref->parent);
if (ret < 0)
goto out;
} }
node = rb_next(node); node = rb_next(node);
if (node) if (node)
ref = rb_entry(node, struct ref, bytenr_node); ref = rb_entry(node, struct ref, bytenr_node);
} while (node && ref->bytenr == parent); } while (node && ref->bytenr == parent);
ret = 0;
out:
return ret;
} }
static int account_one_extent(struct ulist *roots, u64 bytenr, u64 num_bytes) static int account_one_extent(struct ulist *roots, u64 bytenr, u64 num_bytes)
@ -488,6 +498,7 @@ static int account_all_refs(int do_qgroups, u64 search_subvol)
struct rb_node *node; struct rb_node *node;
u64 bytenr, num_bytes; u64 bytenr, num_bytes;
struct ulist *roots = ulist_alloc(0); struct ulist *roots = ulist_alloc(0);
int ret;
node = rb_first(&by_bytenr); node = rb_first(&by_bytenr);
while (node) { while (node) {
@ -511,7 +522,9 @@ static int account_all_refs(int do_qgroups, u64 search_subvol)
goto enomem; goto enomem;
} }
} else { } else {
find_parent_roots(roots, ref->parent); ret = find_parent_roots(roots, ref->parent);
if (ret < 0)
goto enomem;
} }
/* /*