Skip to content

Commit e27c5b9

Browse files
htejunaxboe
authored andcommitted
writeback: remove broken rbtree_postorder_for_each_entry_safe() usage in cgwb_bdi_destroy()
a20135f ("writeback: don't drain bdi_writeback_congested on bdi destruction") added rbtree_postorder_for_each_entry_safe() which is used to remove all entries; however, according to Cody, the iterator isn't safe against operations which may rebalance the tree. Fix it by switching to repeatedly removing rb_first() until empty. Signed-off-by: Tejun Heo <[email protected]> Reported-by: Cody P Schafer <[email protected]> Fixes: a20135f ("writeback: don't drain bdi_writeback_congested on bdi destruction") Link: http://lkml.kernel.org/g/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 0dfc70c commit e27c5b9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

mm/backing-dev.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ static int cgwb_bdi_init(struct backing_dev_info *bdi)
681681
static void cgwb_bdi_destroy(struct backing_dev_info *bdi)
682682
{
683683
struct radix_tree_iter iter;
684-
struct bdi_writeback_congested *congested, *congested_n;
684+
struct rb_node *rbn;
685685
void **slot;
686686

687687
WARN_ON(test_bit(WB_registered, &bdi->wb.state));
@@ -691,9 +691,11 @@ static void cgwb_bdi_destroy(struct backing_dev_info *bdi)
691691
radix_tree_for_each_slot(slot, &bdi->cgwb_tree, &iter, 0)
692692
cgwb_kill(*slot);
693693

694-
rbtree_postorder_for_each_entry_safe(congested, congested_n,
695-
&bdi->cgwb_congested_tree, rb_node) {
696-
rb_erase(&congested->rb_node, &bdi->cgwb_congested_tree);
694+
while ((rbn = rb_first(&bdi->cgwb_congested_tree))) {
695+
struct bdi_writeback_congested *congested =
696+
rb_entry(rbn, struct bdi_writeback_congested, rb_node);
697+
698+
rb_erase(rbn, &bdi->cgwb_congested_tree);
697699
congested->bdi = NULL; /* mark @congested unlinked */
698700
}
699701

0 commit comments

Comments
 (0)