Skip to content

Commit bb25e49

Browse files
codypstorvalds
authored andcommitted
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>
1 parent b182837 commit bb25e49

6 files changed

Lines changed: 17 additions & 114 deletions

File tree

‎fs/ubifs/debug.c‎

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,26 +2118,10 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
21182118
*/
21192119
static void free_inodes(struct fsck_data *fsckd)
21202120
{
2121-
struct rb_node *this = fsckd->inodes.rb_node;
2122-
struct fsck_inode *fscki;
2121+
struct fsck_inode *fscki, *n;
21232122

2124-
while (this) {
2125-
if (this->rb_left)
2126-
this = this->rb_left;
2127-
else if (this->rb_right)
2128-
this = this->rb_right;
2129-
else {
2130-
fscki = rb_entry(this, struct fsck_inode, rb);
2131-
this = rb_parent(this);
2132-
if (this) {
2133-
if (this->rb_left == &fscki->rb)
2134-
this->rb_left = NULL;
2135-
else
2136-
this->rb_right = NULL;
2137-
}
2138-
kfree(fscki);
2139-
}
2140-
}
2123+
rbtree_postorder_for_each_entry_safe(fscki, n, &fsckd->inodes, rb)
2124+
kfree(fscki);
21412125
}
21422126

21432127
/**

‎fs/ubifs/log.c‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -574,27 +574,10 @@ static int done_already(struct rb_root *done_tree, int lnum)
574574
*/
575575
static void destroy_done_tree(struct rb_root *done_tree)
576576
{
577-
struct rb_node *this = done_tree->rb_node;
578-
struct done_ref *dr;
577+
struct done_ref *dr, *n;
579578

580-
while (this) {
581-
if (this->rb_left) {
582-
this = this->rb_left;
583-
continue;
584-
} else if (this->rb_right) {
585-
this = this->rb_right;
586-
continue;
587-
}
588-
dr = rb_entry(this, struct done_ref, rb);
589-
this = rb_parent(this);
590-
if (this) {
591-
if (this->rb_left == &dr->rb)
592-
this->rb_left = NULL;
593-
else
594-
this->rb_right = NULL;
595-
}
579+
rbtree_postorder_for_each_entry_safe(dr, n, done_tree, rb)
596580
kfree(dr);
597-
}
598581
}
599582

600583
/**

‎fs/ubifs/orphan.c‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -815,27 +815,10 @@ static int dbg_find_check_orphan(struct rb_root *root, ino_t inum)
815815

816816
static void dbg_free_check_tree(struct rb_root *root)
817817
{
818-
struct rb_node *this = root->rb_node;
819-
struct check_orphan *o;
818+
struct check_orphan *o, *n;
820819

821-
while (this) {
822-
if (this->rb_left) {
823-
this = this->rb_left;
824-
continue;
825-
} else if (this->rb_right) {
826-
this = this->rb_right;
827-
continue;
828-
}
829-
o = rb_entry(this, struct check_orphan, rb);
830-
this = rb_parent(this);
831-
if (this) {
832-
if (this->rb_left == &o->rb)
833-
this->rb_left = NULL;
834-
else
835-
this->rb_right = NULL;
836-
}
820+
rbtree_postorder_for_each_entry_safe(o, n, root, rb)
837821
kfree(o);
838-
}
839822
}
840823

841824
static int dbg_orphan_check(struct ubifs_info *c, struct ubifs_zbranch *zbr,

‎fs/ubifs/recovery.c‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,29 +1335,14 @@ static void remove_ino(struct ubifs_info *c, ino_t inum)
13351335
*/
13361336
void ubifs_destroy_size_tree(struct ubifs_info *c)
13371337
{
1338-
struct rb_node *this = c->size_tree.rb_node;
1339-
struct size_entry *e;
1338+
struct size_entry *e, *n;
13401339

1341-
while (this) {
1342-
if (this->rb_left) {
1343-
this = this->rb_left;
1344-
continue;
1345-
} else if (this->rb_right) {
1346-
this = this->rb_right;
1347-
continue;
1348-
}
1349-
e = rb_entry(this, struct size_entry, rb);
1340+
rbtree_postorder_for_each_entry_safe(e, n, &c->size_tree, rb) {
13501341
if (e->inode)
13511342
iput(e->inode);
1352-
this = rb_parent(this);
1353-
if (this) {
1354-
if (this->rb_left == &e->rb)
1355-
this->rb_left = NULL;
1356-
else
1357-
this->rb_right = NULL;
1358-
}
13591343
kfree(e);
13601344
}
1345+
13611346
c->size_tree = RB_ROOT;
13621347
}
13631348

‎fs/ubifs/super.c‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -873,26 +873,10 @@ static void free_orphans(struct ubifs_info *c)
873873
*/
874874
static void free_buds(struct ubifs_info *c)
875875
{
876-
struct rb_node *this = c->buds.rb_node;
877-
struct ubifs_bud *bud;
878-
879-
while (this) {
880-
if (this->rb_left)
881-
this = this->rb_left;
882-
else if (this->rb_right)
883-
this = this->rb_right;
884-
else {
885-
bud = rb_entry(this, struct ubifs_bud, rb);
886-
this = rb_parent(this);
887-
if (this) {
888-
if (this->rb_left == &bud->rb)
889-
this->rb_left = NULL;
890-
else
891-
this->rb_right = NULL;
892-
}
893-
kfree(bud);
894-
}
895-
}
876+
struct ubifs_bud *bud, *n;
877+
878+
rbtree_postorder_for_each_entry_safe(bud, n, &c->buds, rb)
879+
kfree(bud);
896880
}
897881

898882
/**

‎fs/ubifs/tnc.c‎

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -178,27 +178,11 @@ static int ins_clr_old_idx_znode(struct ubifs_info *c,
178178
*/
179179
void destroy_old_idx(struct ubifs_info *c)
180180
{
181-
struct rb_node *this = c->old_idx.rb_node;
182-
struct ubifs_old_idx *old_idx;
181+
struct ubifs_old_idx *old_idx, *n;
183182

184-
while (this) {
185-
if (this->rb_left) {
186-
this = this->rb_left;
187-
continue;
188-
} else if (this->rb_right) {
189-
this = this->rb_right;
190-
continue;
191-
}
192-
old_idx = rb_entry(this, struct ubifs_old_idx, rb);
193-
this = rb_parent(this);
194-
if (this) {
195-
if (this->rb_left == &old_idx->rb)
196-
this->rb_left = NULL;
197-
else
198-
this->rb_right = NULL;
199-
}
183+
rbtree_postorder_for_each_entry_safe(old_idx, n, &c->old_idx, rb)
200184
kfree(old_idx);
201-
}
185+
202186
c->old_idx = RB_ROOT;
203187
}
204188

0 commit comments

Comments
 (0)