/* This function looks for a wear leveling entry with medium erase counter, but not greater or equivalent than the lowest erase counter plus WL_FREE_MAX_DIFF/2.  */
static struct ubi_wl_entry* find_mean_wl_entry(struct ubi_device *ubi, struct rb_root *root)
/* This function looks for a wear leveling entry with medium erase counter, but not greater or equivalent than the lowest erase counter plus WL_FREE_MAX_DIFF/2.  */
static struct ubi_wl_entry* find_mean_wl_entry(struct ubi_device *ubi, struct rb_root *root)
{
	struct ubi_wl_entry *e, *first, *last;
	first = rb_entry(rb_first(root), struct ubi_wl_entry, u.rb);
	last = rb_entry(rb_last(root), struct ubi_wl_entry, u.rb);
	if (last->ec - first->ec < WL_FREE_MAX_DIFF) {
		e = rb_entry(root->rb_node, struct ubi_wl_entry, u.rb);
		e = may_reserve_for_fm(ubi, e, root);
	} else
		e = find_wl_entry(ubi, root, WL_FREE_MAX_DIFF/2);
	return e;
}