/* This function locks a logical eraseblock for writing if there is no contention and does nothing if there is contention. Returns %0 in case of success, %1 in case of contention, and and a negative error code in case of failure.  */
static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum)
/* This function locks a logical eraseblock for writing if there is no contention and does nothing if there is contention. Returns %0 in case of success, %1 in case of contention, and and a negative error code in case of failure.  */
static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum)
{
	struct ubi_ltree_entry *le;
	le = ltree_add_entry(ubi, vol_id, lnum);
	if (IS_ERR(le))
		return PTR_ERR(le);
	if (down_write_trylock(&le->mutex))
		return 0;
	spin_lock(&ubi->ltree_lock);
	le->users -= 1;
	ubi_assert(le->users >= 0);
	if (le->users == 0) {
		rb_erase(&le->rb, &ubi->ltree);
		kfree(le);
	}
	spin_unlock(&ubi->ltree_lock);
	return 1;
}