fs/ubifs: use rbtree postorder iteration helper instead of opencoding

Use rbtree_postorder_for_each_entry_safe() to destroy the rbtree instead
of opencoding an alternate postorder iteration that modifies the tree

Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Artem Bityutskiy <dedekind1@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Cody P Schafer
2014-01-23 15:56:08 -08:00
committed by Linus Torvalds
parent b182837ac1
commit bb25e49ff8
6 changed files with 16 additions and 113 deletions

View File

@@ -2118,27 +2118,11 @@ out_free:
*/ */
static void free_inodes(struct fsck_data *fsckd) static void free_inodes(struct fsck_data *fsckd)
{ {
struct rb_node *this = fsckd->inodes.rb_node; struct fsck_inode *fscki, *n;
struct fsck_inode *fscki;
while (this) { rbtree_postorder_for_each_entry_safe(fscki, n, &fsckd->inodes, rb)
if (this->rb_left)
this = this->rb_left;
else if (this->rb_right)
this = this->rb_right;
else {
fscki = rb_entry(this, struct fsck_inode, rb);
this = rb_parent(this);
if (this) {
if (this->rb_left == &fscki->rb)
this->rb_left = NULL;
else
this->rb_right = NULL;
}
kfree(fscki); kfree(fscki);
} }
}
}
/** /**
* check_inodes - checks all inodes. * check_inodes - checks all inodes.

View File

@@ -574,28 +574,11 @@ static int done_already(struct rb_root *done_tree, int lnum)
*/ */
static void destroy_done_tree(struct rb_root *done_tree) static void destroy_done_tree(struct rb_root *done_tree)
{ {
struct rb_node *this = done_tree->rb_node; struct done_ref *dr, *n;
struct done_ref *dr;
while (this) { rbtree_postorder_for_each_entry_safe(dr, n, done_tree, rb)
if (this->rb_left) {
this = this->rb_left;
continue;
} else if (this->rb_right) {
this = this->rb_right;
continue;
}
dr = rb_entry(this, struct done_ref, rb);
this = rb_parent(this);
if (this) {
if (this->rb_left == &dr->rb)
this->rb_left = NULL;
else
this->rb_right = NULL;
}
kfree(dr); kfree(dr);
} }
}
/** /**
* add_node - add a node to the consolidated log. * add_node - add a node to the consolidated log.

View File

@@ -815,28 +815,11 @@ static int dbg_find_check_orphan(struct rb_root *root, ino_t inum)
static void dbg_free_check_tree(struct rb_root *root) static void dbg_free_check_tree(struct rb_root *root)
{ {
struct rb_node *this = root->rb_node; struct check_orphan *o, *n;
struct check_orphan *o;
while (this) { rbtree_postorder_for_each_entry_safe(o, n, root, rb)
if (this->rb_left) {
this = this->rb_left;
continue;
} else if (this->rb_right) {
this = this->rb_right;
continue;
}
o = rb_entry(this, struct check_orphan, rb);
this = rb_parent(this);
if (this) {
if (this->rb_left == &o->rb)
this->rb_left = NULL;
else
this->rb_right = NULL;
}
kfree(o); kfree(o);
} }
}
static int dbg_orphan_check(struct ubifs_info *c, struct ubifs_zbranch *zbr, static int dbg_orphan_check(struct ubifs_info *c, struct ubifs_zbranch *zbr,
void *priv) void *priv)

View File

@@ -1335,29 +1335,14 @@ static void remove_ino(struct ubifs_info *c, ino_t inum)
*/ */
void ubifs_destroy_size_tree(struct ubifs_info *c) void ubifs_destroy_size_tree(struct ubifs_info *c)
{ {
struct rb_node *this = c->size_tree.rb_node; struct size_entry *e, *n;
struct size_entry *e;
while (this) { rbtree_postorder_for_each_entry_safe(e, n, &c->size_tree, rb) {
if (this->rb_left) {
this = this->rb_left;
continue;
} else if (this->rb_right) {
this = this->rb_right;
continue;
}
e = rb_entry(this, struct size_entry, rb);
if (e->inode) if (e->inode)
iput(e->inode); iput(e->inode);
this = rb_parent(this);
if (this) {
if (this->rb_left == &e->rb)
this->rb_left = NULL;
else
this->rb_right = NULL;
}
kfree(e); kfree(e);
} }
c->size_tree = RB_ROOT; c->size_tree = RB_ROOT;
} }

View File

@@ -873,27 +873,11 @@ static void free_orphans(struct ubifs_info *c)
*/ */
static void free_buds(struct ubifs_info *c) static void free_buds(struct ubifs_info *c)
{ {
struct rb_node *this = c->buds.rb_node; struct ubifs_bud *bud, *n;
struct ubifs_bud *bud;
while (this) { rbtree_postorder_for_each_entry_safe(bud, n, &c->buds, rb)
if (this->rb_left)
this = this->rb_left;
else if (this->rb_right)
this = this->rb_right;
else {
bud = rb_entry(this, struct ubifs_bud, rb);
this = rb_parent(this);
if (this) {
if (this->rb_left == &bud->rb)
this->rb_left = NULL;
else
this->rb_right = NULL;
}
kfree(bud); kfree(bud);
} }
}
}
/** /**
* check_volume_empty - check if the UBI volume is empty. * check_volume_empty - check if the UBI volume is empty.

View File

@@ -178,27 +178,11 @@ static int ins_clr_old_idx_znode(struct ubifs_info *c,
*/ */
void destroy_old_idx(struct ubifs_info *c) void destroy_old_idx(struct ubifs_info *c)
{ {
struct rb_node *this = c->old_idx.rb_node; struct ubifs_old_idx *old_idx, *n;
struct ubifs_old_idx *old_idx;
while (this) { rbtree_postorder_for_each_entry_safe(old_idx, n, &c->old_idx, rb)
if (this->rb_left) {
this = this->rb_left;
continue;
} else if (this->rb_right) {
this = this->rb_right;
continue;
}
old_idx = rb_entry(this, struct ubifs_old_idx, rb);
this = rb_parent(this);
if (this) {
if (this->rb_left == &old_idx->rb)
this->rb_left = NULL;
else
this->rb_right = NULL;
}
kfree(old_idx); kfree(old_idx);
}
c->old_idx = RB_ROOT; c->old_idx = RB_ROOT;
} }