/* This function returns PEB @pnum from the protection trees and returns zero in case of success and %-ENODEV if the PEB was not found in the protection trees.  */
static int prot_tree_del(struct ubi_device *ubi, int pnum)
/* This function returns PEB @pnum from the protection trees and returns zero in case of success and %-ENODEV if the PEB was not found in the protection trees.  */
static int prot_tree_del(struct ubi_device *ubi, int pnum)
{
	struct rb_node *p;
	struct ubi_wl_prot_entry *pe = NULL;
	p = ubi->prot.pnum.rb_node;
	while (p) {
		pe = rb_entry(p, struct ubi_wl_prot_entry, rb_pnum);
		if (pnum == pe->e->pnum)
			goto found;
		if (pnum < pe->e->pnum)
			p = p->rb_left;
		else
			p = p->rb_right;
	}
	return -ENODEV;
found:
	ubi_assert(pe->e->pnum == pnum);
	rb_erase(&pe->rb_aec, &ubi->prot.aec);
	rb_erase(&pe->rb_pnum, &ubi->prot.pnum);
	kfree(pe);
	return 0;
}