Commit 94960e8c authored by Tejun Heo's avatar Tejun Heo Committed by Linus Torvalds

sctp: convert to idr_alloc()

Convert to the much saner new idr interface.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarNeil Horman <nhorman@tuxdriver.com>
Acked-by: default avatarVlad Yasevich <vyasevich@gmail.com>
Cc: Sridhar Samudrala <sri@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 9475af6e
...@@ -1591,32 +1591,31 @@ int sctp_assoc_lookup_laddr(struct sctp_association *asoc, ...@@ -1591,32 +1591,31 @@ int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
/* Set an association id for a given association */ /* Set an association id for a given association */
int sctp_assoc_set_id(struct sctp_association *asoc, gfp_t gfp) int sctp_assoc_set_id(struct sctp_association *asoc, gfp_t gfp)
{ {
int assoc_id; bool preload = gfp & __GFP_WAIT;
int error = 0; int ret;
/* If the id is already assigned, keep it. */ /* If the id is already assigned, keep it. */
if (asoc->assoc_id) if (asoc->assoc_id)
return error; return 0;
retry:
if (unlikely(!idr_pre_get(&sctp_assocs_id, gfp)))
return -ENOMEM;
if (preload)
idr_preload(gfp);
spin_lock_bh(&sctp_assocs_id_lock); spin_lock_bh(&sctp_assocs_id_lock);
error = idr_get_new_above(&sctp_assocs_id, (void *)asoc, /* 0 is not a valid id, idr_low is always >= 1 */
idr_low, &assoc_id); ret = idr_alloc(&sctp_assocs_id, asoc, idr_low, 0, GFP_NOWAIT);
if (!error) { if (ret >= 0) {
idr_low = assoc_id + 1; idr_low = ret + 1;
if (idr_low == INT_MAX) if (idr_low == INT_MAX)
idr_low = 1; idr_low = 1;
} }
spin_unlock_bh(&sctp_assocs_id_lock); spin_unlock_bh(&sctp_assocs_id_lock);
if (error == -EAGAIN) if (preload)
goto retry; idr_preload_end();
else if (error) if (ret < 0)
return error; return ret;
asoc->assoc_id = (sctp_assoc_t) assoc_id; asoc->assoc_id = (sctp_assoc_t)ret;
return error; return 0;
} }
/* Free the ASCONF queue */ /* Free the ASCONF queue */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment