/* The function returns a physical erase block with a given maximal number and removes it from the wl subsystem. Must be called with wl_lock held!  */
struct ubi_wl_entry* ubi_wl_get_fm_peb(struct ubi_device *ubi, int anchor)
/* The function returns a physical erase block with a given maximal number and removes it from the wl subsystem. Must be called with wl_lock held!  */
struct ubi_wl_entry* ubi_wl_get_fm_peb(struct ubi_device *ubi, int anchor)
{
	struct ubi_wl_entry *e = NULL;
	if (!ubi->free.rb_node || (ubi->free_count - ubi->beb_rsvd_pebs < 1))
		goto out;
	if (anchor)
		e = find_anchor_wl_entry(&ubi->free);
	else
		e = find_mean_wl_entry(ubi, &ubi->free);
	if (!e)
		goto out;
	self_check_in_wl_tree(ubi, e, &ubi->free);
	rb_erase(&e->u.rb, &ubi->free);
	ubi->free_count--;
out:
	return e;
}