/* ubi_ensure_anchor_pebs - schedule wear-leveling to produce an anchor PEB. @ubi: UBI device description object  */
int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
/* ubi_ensure_anchor_pebs - schedule wear-leveling to produce an anchor PEB. @ubi: UBI device description object  */
int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
{
	struct ubi_work *wrk;
	spin_lock(&ubi->wl_lock);
	if (ubi->wl_scheduled) {
		spin_unlock(&ubi->wl_lock);
		return 0;
	}
	ubi->wl_scheduled = 1;
	spin_unlock(&ubi->wl_lock);
	wrk = kmalloc(sizeof(struct ubi_work), GFP_NOFS);
	if (!wrk) {
		spin_lock(&ubi->wl_lock);
		ubi->wl_scheduled = 0;
		spin_unlock(&ubi->wl_lock);
		return -ENOMEM;
	}
	wrk->anchor = 1;
	wrk->func = &wear_leveling_worker;
	schedule_ubi_work(ubi, wrk);
	return 0;
}