]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
atm/nicstar: convert to idr_alloc()
authorTejun Heo <tj@kernel.org>
Wed, 20 Feb 2013 02:16:10 +0000 (13:16 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 20 Feb 2013 05:53:43 +0000 (16:53 +1100)
Convert to the much saner new idr interface.  The existing code looks
buggy to me - ID 0 is treated as no-ID but allocation specifies 0 as
lower limit and there's no error handling after partial success.  This
conversion keeps the bugs unchanged.

Only compile tested.

v2: id1 and id2 are now directly used for -errno return and thus
    should be signed.  Make them int instead of u32.  This was spotted
    by kbuild test robot.

v3: Further simplify as suggested by Chas Williams.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Chas Williams <chas@cmf.nrl.navy.mil>
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/atm/nicstar.c

index 628787ed999c521d15800a38fb775746a6ae9735..6587dc295eb0e85178a29c11547c0bf04d410de6 100644 (file)
@@ -949,11 +949,10 @@ static void free_scq(ns_dev *card, scq_info *scq, struct atm_vcc *vcc)
 static void push_rxbufs(ns_dev * card, struct sk_buff *skb)
 {
        struct sk_buff *handle1, *handle2;
-       u32 id1 = 0, id2 = 0;
+       int id1, id2;
        u32 addr1, addr2;
        u32 stat;
        unsigned long flags;
-       int err;
 
        /* *BARF* */
        handle2 = NULL;
@@ -1026,23 +1025,12 @@ static void push_rxbufs(ns_dev * card, struct sk_buff *skb)
                                card->lbfqc += 2;
                }
 
-               do {
-                       if (!idr_pre_get(&card->idr, GFP_ATOMIC)) {
-                               printk(KERN_ERR
-                                      "nicstar%d: no free memory for idr\n",
-                                      card->index);
-                               goto out;
-                       }
-
-                       if (!id1)
-                               err = idr_get_new_above(&card->idr, handle1, 0, &id1);
-
-                       if (!id2 && err == 0)
-                               err = idr_get_new_above(&card->idr, handle2, 0, &id2);
-
-               } while (err == -EAGAIN);
+               id1 = idr_alloc(&card->idr, handle1, 0, 0, GFP_ATOMIC);
+               if (id1 < 0)
+                       goto out;
 
-               if (err)
+               id2 = idr_alloc(&card->idr, handle2, 0, 0, GFP_ATOMIC);
+               if (id2 < 0)
                        goto out;
 
                spin_lock_irqsave(&card->res_lock, flags);