/* Select a LPT LEB for LPT garbage collection and call 'lpt_gc_lnum()'. Returns %0 on success and a negative error code on failure.  */
static int lpt_gc(struct ubifs_info *c)
/* Select a LPT LEB for LPT garbage collection and call 'lpt_gc_lnum()'. Returns %0 on success and a negative error code on failure.  */
static int lpt_gc(struct ubifs_info *c)
{
	int i, lnum = -1, dirty = 0;
	mutex_lock(&c->lp_mutex);
	for (i = 0; i < c->lpt_lebs; i++) {
		ubifs_assert(!c->ltab[i].tgc);
		if (i + c->lpt_first == c->nhead_lnum ||
		    c->ltab[i].free + c->ltab[i].dirty == c->leb_size)
			continue;
		if (c->ltab[i].dirty > dirty) {
			dirty = c->ltab[i].dirty;
			lnum = i + c->lpt_first;
		}
	}
	mutex_unlock(&c->lp_mutex);
	if (lnum == -1)
		return -ENOSPC;
	return lpt_gc_lnum(c, lnum);
}