From patchwork Wed Feb 6 19:39:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 218725 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 391152C02C9 for ; Thu, 7 Feb 2013 06:52:23 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964813Ab3BFTuD (ORCPT ); Wed, 6 Feb 2013 14:50:03 -0500 Received: from mail-ob0-f170.google.com ([209.85.214.170]:41009 "EHLO mail-ob0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964798Ab3BFTuA (ORCPT ); Wed, 6 Feb 2013 14:50:00 -0500 Received: by mail-ob0-f170.google.com with SMTP id wc20so1896845obb.29 for ; Wed, 06 Feb 2013 11:49:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=iSpzgdc/NR0bp9EBeKCCXKCeb0QVnSnhH+tK2tucjao=; b=q2y8N+YY7E16so439kIAaBAtd7ahWhl+E0VUp2jehWYXbn3UWCAqbevuP7LhAEm4gX MwCOZv+bnuOt2qZGDgjnD1w4ISlp49saUg9aupDeeGxxRM75/d0zxwc2e9bxPEe58RBj E+qR3MJDsQZ3j84dzldPS33/sHaptddhIlO/CBAwukPSuha6O5FU0YWP53qvKMRhay8i 4ulaurYvW7hFVC+FYa6l8Q4zfd7yCBSIUymyf4kTOdI31V7Ta0I6qQrWdTVqFV6xKheX 2bzjnsU6qMxD1Hjp89Nl+jY/lsgM77ww4aZDg/Q9uzjUuoKJNFnUzbld0o/5JMkXA8hc +94g== X-Received: by 10.60.25.138 with SMTP id c10mr23552801oeg.12.1360180199275; Wed, 06 Feb 2013 11:49:59 -0800 (PST) Received: from htj.dyndns.org (c-69-181-251-227.hsd1.ca.comcast.net. [69.181.251.227]) by mx.google.com with ESMTPS id l5sm39989590pax.10.2013.02.06.11.49.57 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 06 Feb 2013 11:49:58 -0800 (PST) From: Tejun Heo To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Tejun Heo , netdev@vger.kernel.org Subject: [PATCH 24/77] atm/nicstar: convert to idr_alloc() Date: Wed, 6 Feb 2013 11:39:56 -0800 Message-Id: <1360179649-22465-25-git-send-email-tj@kernel.org> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1360179649-22465-1-git-send-email-tj@kernel.org> References: <1360179649-22465-1-git-send-email-tj@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Acked-by: Chas Williams Reported-by: kbuild test robot Cc: netdev@vger.kernel.org --- drivers/atm/nicstar.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c index 628787e..6587dc2 100644 --- a/drivers/atm/nicstar.c +++ b/drivers/atm/nicstar.c @@ -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);