diff options
| author | Cody P Schafer <cody@linux.vnet.ibm.com> | 2014-01-23 18:56:08 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-01-23 19:37:03 -0500 |
| commit | bb25e49ff8ab0ef0b3c073c09d55cf10ef8a2aa0 (patch) | |
| tree | 0eb5d1ca02d4e9caccd9716e35d5baa448eb73c8 | |
| parent | b182837ac111e87f8e82cbcb0046449d9412187f (diff) | |
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>
| -rw-r--r-- | fs/ubifs/debug.c | 22 | ||||
| -rw-r--r-- | fs/ubifs/log.c | 21 | ||||
| -rw-r--r-- | fs/ubifs/orphan.c | 21 | ||||
| -rw-r--r-- | fs/ubifs/recovery.c | 21 | ||||
| -rw-r--r-- | fs/ubifs/super.c | 24 | ||||
| -rw-r--r-- | fs/ubifs/tnc.c | 22 |
6 files changed, 17 insertions, 114 deletions
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index cc1febd8fadf..5157b866a853 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c | |||
| @@ -2118,26 +2118,10 @@ out_free: | |||
| 2118 | */ | 2118 | */ |
| 2119 | static void free_inodes(struct fsck_data *fsckd) | 2119 | static void free_inodes(struct fsck_data *fsckd) |
| 2120 | { | 2120 | { |
| 2121 | struct rb_node *this = fsckd->inodes.rb_node; | 2121 | struct fsck_inode *fscki, *n; |
| 2122 | struct fsck_inode *fscki; | ||
| 2123 | 2122 | ||
| 2124 | while (this) { | 2123 | rbtree_postorder_for_each_entry_safe(fscki, n, &fsckd->inodes, rb) |
| 2125 | if (this->rb_left) | 2124 | kfree(fscki); |
| 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 | } | ||
| 2141 | } | 2125 | } |
| 2142 | 2126 | ||
| 2143 | /** | 2127 | /** |
diff --git a/fs/ubifs/log.c b/fs/ubifs/log.c index 36bd4efd0819..a902c5919e42 100644 --- a/fs/ubifs/log.c +++ b/fs/ubifs/log.c | |||
| @@ -574,27 +574,10 @@ static int done_already(struct rb_root *done_tree, int lnum) | |||
| 574 | */ | 574 | */ |
| 575 | static void destroy_done_tree(struct rb_root *done_tree) | 575 | static void destroy_done_tree(struct rb_root *done_tree) |
| 576 | { | 576 | { |
| 577 | struct rb_node *this = done_tree->rb_node; | 577 | struct done_ref *dr, *n; |
| 578 | struct done_ref *dr; | ||
| 579 | 578 | ||
| 580 | while (this) { | 579 | rbtree_postorder_for_each_entry_safe(dr, n, done_tree, rb) |
| 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 | } | ||
| 596 | kfree(dr); | 580 | kfree(dr); |
| 597 | } | ||
| 598 | } | 581 | } |
| 599 | 582 | ||
| 600 | /** | 583 | /** |
diff --git a/fs/ubifs/orphan.c b/fs/ubifs/orphan.c index ba32da3fe08a..f1c3e5a1b315 100644 --- a/fs/ubifs/orphan.c +++ b/fs/ubifs/orphan.c | |||
| @@ -815,27 +815,10 @@ static int dbg_find_check_orphan(struct rb_root *root, ino_t inum) | |||
| 815 | 815 | ||
| 816 | static void dbg_free_check_tree(struct rb_root *root) | 816 | static void dbg_free_check_tree(struct rb_root *root) |
| 817 | { | 817 | { |
| 818 | struct rb_node *this = root->rb_node; | 818 | struct check_orphan *o, *n; |
| 819 | struct check_orphan *o; | ||
| 820 | 819 | ||
| 821 | while (this) { | 820 | rbtree_postorder_for_each_entry_safe(o, n, root, rb) |
| 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 | } | ||
| 837 | kfree(o); | 821 | kfree(o); |
| 838 | } | ||
| 839 | } | 822 | } |
| 840 | 823 | ||
| 841 | static int dbg_orphan_check(struct ubifs_info *c, struct ubifs_zbranch *zbr, | 824 | static int dbg_orphan_check(struct ubifs_info *c, struct ubifs_zbranch *zbr, |
diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c index 065096e36ed9..c14adb2f420c 100644 --- a/fs/ubifs/recovery.c +++ b/fs/ubifs/recovery.c | |||
| @@ -1335,29 +1335,14 @@ static void remove_ino(struct ubifs_info *c, ino_t inum) | |||
| 1335 | */ | 1335 | */ |
| 1336 | void ubifs_destroy_size_tree(struct ubifs_info *c) | 1336 | void ubifs_destroy_size_tree(struct ubifs_info *c) |
| 1337 | { | 1337 | { |
| 1338 | struct rb_node *this = c->size_tree.rb_node; | 1338 | struct size_entry *e, *n; |
| 1339 | struct size_entry *e; | ||
| 1340 | 1339 | ||
| 1341 | while (this) { | 1340 | rbtree_postorder_for_each_entry_safe(e, n, &c->size_tree, rb) { |
| 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); | ||
| 1350 | if (e->inode) | 1341 | if (e->inode) |
| 1351 | iput(e->inode); | 1342 | 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 | } | ||
| 1359 | kfree(e); | 1343 | kfree(e); |
| 1360 | } | 1344 | } |
| 1345 | |||
| 1361 | c->size_tree = RB_ROOT; | 1346 | c->size_tree = RB_ROOT; |
| 1362 | } | 1347 | } |
| 1363 | 1348 | ||
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index f69daa514a57..5ded8490c0c6 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c | |||
| @@ -873,26 +873,10 @@ static void free_orphans(struct ubifs_info *c) | |||
| 873 | */ | 873 | */ |
| 874 | static void free_buds(struct ubifs_info *c) | 874 | static void free_buds(struct ubifs_info *c) |
| 875 | { | 875 | { |
| 876 | struct rb_node *this = c->buds.rb_node; | 876 | struct ubifs_bud *bud, *n; |
| 877 | struct ubifs_bud *bud; | 877 | |
| 878 | 878 | rbtree_postorder_for_each_entry_safe(bud, n, &c->buds, rb) | |
| 879 | while (this) { | 879 | kfree(bud); |
| 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 | } | ||
| 896 | } | 880 | } |
| 897 | 881 | ||
| 898 | /** | 882 | /** |
diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c index 349f31a30f40..9083bc7ed4ae 100644 --- a/fs/ubifs/tnc.c +++ b/fs/ubifs/tnc.c | |||
| @@ -178,27 +178,11 @@ static int ins_clr_old_idx_znode(struct ubifs_info *c, | |||
| 178 | */ | 178 | */ |
| 179 | void destroy_old_idx(struct ubifs_info *c) | 179 | void destroy_old_idx(struct ubifs_info *c) |
| 180 | { | 180 | { |
| 181 | struct rb_node *this = c->old_idx.rb_node; | 181 | struct ubifs_old_idx *old_idx, *n; |
| 182 | struct ubifs_old_idx *old_idx; | ||
| 183 | 182 | ||
| 184 | while (this) { | 183 | rbtree_postorder_for_each_entry_safe(old_idx, n, &c->old_idx, rb) |
| 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 | } | ||
| 200 | kfree(old_idx); | 184 | kfree(old_idx); |
| 201 | } | 185 | |
| 202 | c->old_idx = RB_ROOT; | 186 | c->old_idx = RB_ROOT; |
| 203 | } | 187 | } |
| 204 | 188 | ||
