fs/ubifs: use rbtree postorder iteration helper instead of opencoding
authorCody P Schafer <cody@linux.vnet.ibm.com>
Thu, 23 Jan 2014 23:56:08 +0000 (15:56 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 24 Jan 2014 00:37:03 +0000 (16:37 -0800)
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>
fs/ubifs/debug.c
fs/ubifs/log.c
fs/ubifs/orphan.c
fs/ubifs/recovery.c
fs/ubifs/super.c
fs/ubifs/tnc.c

index cc1febd8fadf730ddd2e2dfb78315798508aa408..5157b866a853cf76cfd6bef1c6fd6ab4b49123bf 100644 (file)
@@ -2118,26 +2118,10 @@ out_free:
  */
 static void free_inodes(struct fsck_data *fsckd)
 {
-       struct rb_node *this = fsckd->inodes.rb_node;
-       struct fsck_inode *fscki;
+       struct fsck_inode *fscki, *n;
 
-       while (this) {
-               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);
-               }
-       }
+       rbtree_postorder_for_each_entry_safe(fscki, n, &fsckd->inodes, rb)
+               kfree(fscki);
 }
 
 /**
index 36bd4efd0819e96ee299acd030f24fa7113e4fb2..a902c5919e423ca619fcf0508345909b51ec99f8 100644 (file)
@@ -574,27 +574,10 @@ static int done_already(struct rb_root *done_tree, int lnum)
  */
 static void destroy_done_tree(struct rb_root *done_tree)
 {
-       struct rb_node *this = done_tree->rb_node;
-       struct done_ref *dr;
+       struct done_ref *dr, *n;
 
-       while (this) {
-               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;
-               }
+       rbtree_postorder_for_each_entry_safe(dr, n, done_tree, rb)
                kfree(dr);
-       }
 }
 
 /**
index ba32da3fe08afa059f750fd18131f21c523376f0..f1c3e5a1b31554c4fbd9c9710d5925ad90682cb1 100644 (file)
@@ -815,27 +815,10 @@ static int dbg_find_check_orphan(struct rb_root *root, ino_t inum)
 
 static void dbg_free_check_tree(struct rb_root *root)
 {
-       struct rb_node *this = root->rb_node;
-       struct check_orphan *o;
+       struct check_orphan *o, *n;
 
-       while (this) {
-               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;
-               }
+       rbtree_postorder_for_each_entry_safe(o, n, root, rb)
                kfree(o);
-       }
 }
 
 static int dbg_orphan_check(struct ubifs_info *c, struct ubifs_zbranch *zbr,
index 065096e36ed9733a14f96090decb3131c0e0d184..c14adb2f420cb09c48fef049bf6d246b8d22cd28 100644 (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)
 {
-       struct rb_node *this = c->size_tree.rb_node;
-       struct size_entry *e;
+       struct size_entry *e, *n;
 
-       while (this) {
-               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);
+       rbtree_postorder_for_each_entry_safe(e, n, &c->size_tree, rb) {
                if (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);
        }
+
        c->size_tree = RB_ROOT;
 }
 
index f69daa514a57a0827a55c47f4680dcb5e69ec746..5ded8490c0c66cca3a6dea286aec8e700bc24e44 100644 (file)
@@ -873,26 +873,10 @@ static void free_orphans(struct ubifs_info *c)
  */
 static void free_buds(struct ubifs_info *c)
 {
-       struct rb_node *this = c->buds.rb_node;
-       struct ubifs_bud *bud;
-
-       while (this) {
-               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);
-               }
-       }
+       struct ubifs_bud *bud, *n;
+
+       rbtree_postorder_for_each_entry_safe(bud, n, &c->buds, rb)
+               kfree(bud);
 }
 
 /**
index 349f31a30f401cb488a595de91cec30cfbf9d647..9083bc7ed4ae49f5d9550c20c1943400860114ab 100644 (file)
@@ -178,27 +178,11 @@ static int ins_clr_old_idx_znode(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;
+       struct ubifs_old_idx *old_idx, *n;
 
-       while (this) {
-               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;
-               }
+       rbtree_postorder_for_each_entry_safe(old_idx, n, &c->old_idx, rb)
                kfree(old_idx);
-       }
+
        c->old_idx = RB_ROOT;
 }