Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Cody P Schafer and committed by
Linus Torvalds
d1866bd0 bb25e49f

+8 -58
+4 -29
fs/ext4/block_validity.c
··· 180 180 /* Called when the filesystem is unmounted */ 181 181 void ext4_release_system_zone(struct super_block *sb) 182 182 { 183 - struct rb_node *n = EXT4_SB(sb)->system_blks.rb_node; 184 - struct rb_node *parent; 185 - struct ext4_system_zone *entry; 183 + struct ext4_system_zone *entry, *n; 186 184 187 - while (n) { 188 - /* Do the node's children first */ 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); 185 + rbtree_postorder_for_each_entry_safe(entry, n, 186 + &EXT4_SB(sb)->system_blks, node) 205 187 kmem_cache_free(ext4_system_zone_cachep, entry); 206 - if (!parent) 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 - } 188 + 214 189 EXT4_SB(sb)->system_blks = RB_ROOT; 215 190 } 216 191
+4 -29
fs/ext4/dir.c
··· 353 353 */ 354 354 static void free_rb_tree_fname(struct rb_root *root) 355 355 { 356 - struct rb_node *n = root->rb_node; 357 - struct rb_node *parent; 358 - struct fname *fname; 356 + struct fname *fname, *next; 359 357 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); 358 + rbtree_postorder_for_each_entry_safe(fname, next, root, rb_hash) 378 359 while (fname) { 379 360 struct fname *old = fname; 380 361 fname = fname->next; 381 362 kfree(old); 382 363 } 383 - if (!parent) 384 - *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 - } 364 + 365 + *root = RB_ROOT; 391 366 } 392 367 393 368