Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3594eb28 authored by Tejun Heo's avatar Tejun Heo Committed by Linus Torvalds
Browse files

idr: refactor idr_get_new_above()



Move slot filling to idr_fill_slot() from idr_get_new_above_int() and
make idr_get_new_above() directly call it.  idr_get_new_above_int() is
no longer needed and removed.

This will be used to implement a new ID allocation interface.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 12d1b439
Loading
Loading
Loading
Loading
+12 −18
Original line number Diff line number Diff line
@@ -278,26 +278,17 @@ static int idr_get_empty_slot(struct idr *idp, int starting_id,
	return(v);
}

static int idr_get_new_above_int(struct idr *idp, void *ptr, int starting_id)
{
	struct idr_layer *pa[MAX_IDR_LEVEL];
	int id;

	id = idr_get_empty_slot(idp, starting_id, pa);
	if (id >= 0) {
/*
		 * Successfully found an empty slot.  Install the user
		 * pointer and mark the slot full.
 * @id and @pa are from a successful allocation from idr_get_empty_slot().
 * Install the user pointer @ptr and mark the slot full.
 */
		rcu_assign_pointer(pa[0]->ary[id & IDR_MASK],
				(struct idr_layer *)ptr);
static void idr_fill_slot(void *ptr, int id, struct idr_layer **pa)
{
	rcu_assign_pointer(pa[0]->ary[id & IDR_MASK], (struct idr_layer *)ptr);
	pa[0]->count++;
	idr_mark_full(pa, id);
}

	return id;
}

/**
 * idr_get_new_above - allocate new idr entry above or equal to a start id
 * @idp: idr handle
@@ -318,11 +309,14 @@ static int idr_get_new_above_int(struct idr *idp, void *ptr, int starting_id)
 */
int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id)
{
	struct idr_layer *pa[MAX_IDR_LEVEL];
	int rv;

	rv = idr_get_new_above_int(idp, ptr, starting_id);
	rv = idr_get_empty_slot(idp, starting_id, pa);
	if (rv < 0)
		return rv == -ENOMEM ? -EAGAIN : rv;

	idr_fill_slot(ptr, rv, pa);
	*id = rv;
	return 0;
}