Commit b051f6edc29c084a6440e9731bc85d95b6b95e14

Authored by Tejun Heo
Committed by Linus Torvalds
1 parent c718aa652d

atm/nicstar: convert to idr_alloc()

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.

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>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 6 additions and 18 deletions Side-by-side Diff

drivers/atm/nicstar.c
... ... @@ -949,11 +949,10 @@
949 949 static void push_rxbufs(ns_dev * card, struct sk_buff *skb)
950 950 {
951 951 struct sk_buff *handle1, *handle2;
952   - u32 id1 = 0, id2 = 0;
  952 + int id1, id2;
953 953 u32 addr1, addr2;
954 954 u32 stat;
955 955 unsigned long flags;
956   - int err;
957 956  
958 957 /* *BARF* */
959 958 handle2 = NULL;
960 959  
... ... @@ -1026,23 +1025,12 @@
1026 1025 card->lbfqc += 2;
1027 1026 }
1028 1027  
1029   - do {
1030   - if (!idr_pre_get(&card->idr, GFP_ATOMIC)) {
1031   - printk(KERN_ERR
1032   - "nicstar%d: no free memory for idr\n",
1033   - card->index);
1034   - goto out;
1035   - }
  1028 + id1 = idr_alloc(&card->idr, handle1, 0, 0, GFP_ATOMIC);
  1029 + if (id1 < 0)
  1030 + goto out;
1036 1031  
1037   - if (!id1)
1038   - err = idr_get_new_above(&card->idr, handle1, 0, &id1);
1039   -
1040   - if (!id2 && err == 0)
1041   - err = idr_get_new_above(&card->idr, handle2, 0, &id2);
1042   -
1043   - } while (err == -EAGAIN);
1044   -
1045   - if (err)
  1032 + id2 = idr_alloc(&card->idr, handle2, 0, 0, GFP_ATOMIC);
  1033 + if (id2 < 0)
1046 1034 goto out;
1047 1035  
1048 1036 spin_lock_irqsave(&card->res_lock, flags);