aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorCody P Schafer <cody@linux.vnet.ibm.com>2014-01-23 18:56:10 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-01-23 19:37:03 -0500
commitd1866bd06101eb8ab2bb9d180b47c052c04b7cee (patch)
tree0bd031db9537dfc911f22c91e8612b79d5438aab /fs
parentbb25e49ff8ab0ef0b3c073c09d55cf10ef8a2aa0 (diff)
fs/ext4: 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> Reviewed-by: Jan Kara <jack@suse.cz> Cc: Michel Lespinasse <walken@google.com> Cc: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/ext4/block_validity.c33
-rw-r--r--fs/ext4/dir.c35
2 files changed, 9 insertions, 59 deletions
diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c
index 3f11656bd72e..41eb9dcfac7e 100644
--- a/fs/ext4/block_validity.c
+++ b/fs/ext4/block_validity.c
@@ -180,37 +180,12 @@ int ext4_setup_system_zone(struct super_block *sb)
180/* Called when the filesystem is unmounted */ 180/* Called when the filesystem is unmounted */
181void ext4_release_system_zone(struct super_block *sb) 181void ext4_release_system_zone(struct super_block *sb)
182{ 182{
183 struct rb_node *n = EXT4_SB(sb)->system_blks.rb_node; 183 struct ext4_system_zone *entry, *n;
184 struct rb_node *parent;
185 struct ext4_system_zone *entry;
186 184
187 while (n) { 185 rbtree_postorder_for_each_entry_safe(entry, n,
188 /* Do the node's children first */ 186 &EXT4_SB(sb)->system_blks, node)
189 if (n->rb_left) {
190 n = n->rb_left;
191 continue;
192 }
193 if (n->rb_right) {
194 n = n->rb_right;
195 continue;
196 }
197 /*
198 * The node has no children; free it, and then zero
199 * out parent's link to it. Finally go to the
200 * beginning of the loop and try to free the parent
201 * node.
202 */
203 parent = rb_parent(n);
204 entry = rb_entry(n, struct ext4_system_zone, node);
205 kmem_cache_free(ext4_system_zone_cachep, entry); 187 kmem_cache_free(ext4_system_zone_cachep, entry);
206 if (!parent) 188
207 EXT4_SB(sb)->system_blks = RB_ROOT;
208 else if (parent->rb_left == n)
209 parent->rb_left = NULL;
210 else if (parent->rb_right == n)
211 parent->rb_right = NULL;
212 n = parent;
213 }
214 EXT4_SB(sb)->system_blks = RB_ROOT; 189 EXT4_SB(sb)->system_blks = RB_ROOT;
215} 190}
216 191
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 680bb3388919..d638c57e996e 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -353,41 +353,16 @@ struct fname {
353 */ 353 */
354static void free_rb_tree_fname(struct rb_root *root) 354static void free_rb_tree_fname(struct rb_root *root)
355{ 355{
356 struct rb_node *n = root->rb_node; 356 struct fname *fname, *next;
357 struct rb_node *parent; 357
358 struct fname *fname; 358 rbtree_postorder_for_each_entry_safe(fname, next, root, rb_hash)
359
360 while (n) {
361 /* Do the node's children first */
362 if (n->rb_left) {
363 n = n->rb_left;
364 continue;
365 }
366 if (n->rb_right) {
367 n = n->rb_right;
368 continue;
369 }
370 /*
371 * The node has no children; free it, and then zero
372 * out parent's link to it. Finally go to the
373 * beginning of the loop and try to free the parent
374 * node.
375 */
376 parent = rb_parent(n);
377 fname = rb_entry(n, struct fname, rb_hash);
378 while (fname) { 359 while (fname) {
379 struct fname *old = fname; 360 struct fname *old = fname;
380 fname = fname->next; 361 fname = fname->next;
381 kfree(old); 362 kfree(old);
382 } 363 }
383 if (!parent) 364
384 *root = RB_ROOT; 365 *root = RB_ROOT;
385 else if (parent->rb_left == n)
386 parent->rb_left = NULL;
387 else if (parent->rb_right == n)
388 parent->rb_right = NULL;
389 n = parent;
390 }
391} 366}
392 367
393 368