/* This function returns zero in case of success and a negative error code in case of failure.  */
static int do_work(struct ubi_device *ubi)
/* This function returns zero in case of success and a negative error code in case of failure.  */
static int do_work(struct ubi_device *ubi)
{
	int err;
	struct ubi_work *wrk;
	cond_resched();
	down_read(&ubi->work_sem);
	spin_lock(&ubi->wl_lock);
	if (list_empty(&ubi->works)) {
		spin_unlock(&ubi->wl_lock);
		up_read(&ubi->work_sem);
		return 0;
	}
	wrk = list_entry(ubi->works.next, struct ubi_work, list);
	list_del(&wrk->list);
	ubi->works_count -= 1;
	ubi_assert(ubi->works_count >= 0);
	spin_unlock(&ubi->wl_lock);
	err = wrk->func(ubi, wrk, 0);
	if (err)
		ubi_err(ubi, "work failed with error code %d", err);
	up_read(&ubi->work_sem);
	return err;
}