]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
sctp: convert to idr_alloc()
authorTejun Heo <tj@kernel.org>
Thu, 28 Feb 2013 01:05:00 +0000 (17:05 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Feb 2013 03:10:20 +0000 (19:10 -0800)
Convert to the much saner new idr interface.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Cc: Sridhar Samudrala <sri@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
net/sctp/associola.c

index 2f95f5a5145dfe797ee30764733e4e349d20f7e0..43cd0dd9149d42e2739985bd8bb4ea15c977de06 100644 (file)
@@ -1591,32 +1591,31 @@ int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
 /* Set an association id for a given association */
 int sctp_assoc_set_id(struct sctp_association *asoc, gfp_t gfp)
 {
-       int assoc_id;
-       int error = 0;
+       bool preload = gfp & __GFP_WAIT;
+       int ret;
 
        /* If the id is already assigned, keep it. */
        if (asoc->assoc_id)
-               return error;
-retry:
-       if (unlikely(!idr_pre_get(&sctp_assocs_id, gfp)))
-               return -ENOMEM;
+               return 0;
 
+       if (preload)
+               idr_preload(gfp);
        spin_lock_bh(&sctp_assocs_id_lock);
-       error = idr_get_new_above(&sctp_assocs_id, (void *)asoc,
-                                   idr_low, &assoc_id);
-       if (!error) {
-               idr_low = assoc_id + 1;
+       /* 0 is not a valid id, idr_low is always >= 1 */
+       ret = idr_alloc(&sctp_assocs_id, asoc, idr_low, 0, GFP_NOWAIT);
+       if (ret >= 0) {
+               idr_low = ret + 1;
                if (idr_low == INT_MAX)
                        idr_low = 1;
        }
        spin_unlock_bh(&sctp_assocs_id_lock);
-       if (error == -EAGAIN)
-               goto retry;
-       else if (error)
-               return error;
+       if (preload)
+               idr_preload_end();
+       if (ret < 0)
+               return ret;
 
-       asoc->assoc_id = (sctp_assoc_t) assoc_id;
-       return error;
+       asoc->assoc_id = (sctp_assoc_t)ret;
+       return 0;
 }
 
 /* Free the ASCONF queue */