From patchwork Mon Feb 4 17:52:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v2,02/14] atm/nicstar: don't use idr_remove_all() Date: Mon, 04 Feb 2013 07:52:10 -0000 From: Tejun Heo X-Patchwork-Id: 218018 Message-Id: <20130204175210.GQ27963@mtj.dyndns.org> To: akpm@linux-foundation.org Cc: rusty@rustcorp.com.au, linux-kernel@vger.kernel.org, Chas Williams , netdev@vger.kernel.org Subject: 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. 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. Signed-off-by: Tejun Heo Acked-by: Chas Williams Reported-by: kbuild test robot Cc: netdev@vger.kernel.org --- drivers/atm/nicstar.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/drivers/atm/nicstar.c +++ b/drivers/atm/nicstar.c @@ -949,7 +949,7 @@ static void free_scq(ns_dev *card, scq_i static void push_rxbufs(ns_dev * card, struct sk_buff *skb) { struct sk_buff *handle1, *handle2; - u32 id1 = 0, id2 = 0; + int id1 = 0, id2 = 0; u32 addr1, addr2; u32 stat; unsigned long flags; @@ -1026,24 +1026,21 @@ static void push_rxbufs(ns_dev * card, s 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); + if (id1 < 0) { + id1 = idr_alloc(&card->idr, handle1, 0, 0, GFP_ATOMIC); + if (id1 < 0) { + err = id1; 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); - - if (err) - goto out; + if (id2 < 0) { + id2 = idr_alloc(&card->idr, handle2, 0, 0, GFP_ATOMIC); + if (id2 < 0) { + err = id2; + goto out; + } + } spin_lock_irqsave(&card->res_lock, flags); while (CMD_BUSY(card)) ;