/* tree_destroy - destroy an RB-tree. @ubi: UBI device description object @root: the root of the tree to destroy  */
static void tree_destroy(struct ubi_device *ubi, struct rb_root *root)
/* tree_destroy - destroy an RB-tree. @ubi: UBI device description object @root: the root of the tree to destroy  */
static void tree_destroy(struct ubi_device *ubi, struct rb_root *root)
{
	struct rb_node *rb;
	struct ubi_wl_entry *e;
	rb = root->rb_node;
	while (rb) {
		if (rb->rb_left)
			rb = rb->rb_left;
		else if (rb->rb_right)
			rb = rb->rb_right;
		else {
			e = rb_entry(rb, struct ubi_wl_entry, u.rb);
			rb = rb_parent(rb);
			if (rb) {
				if (rb->rb_left == &e->u.rb)
					rb->rb_left = NULL;
				else
					rb->rb_right = NULL;
			}
			wl_entry_destroy(ubi, e);
		}
	}
}