* [PATCH 09/62] atm/nicstar: convert to idr_alloc() [not found] <1359854463-2538-1-git-send-email-tj@kernel.org> @ 2013-02-03 1:20 ` Tejun Heo 2013-02-04 14:04 ` chas williams - CONTRACTOR 2013-02-04 18:37 ` [PATCH v3 " Tejun Heo 0 siblings, 2 replies; 5+ messages in thread From: Tejun Heo @ 2013-02-03 1:20 UTC (permalink / raw) To: akpm Cc: linux-kernel, rusty, bfields, skinsbursky, ebiederm, jmorris, axboe, Tejun Heo, Chas Williams, netdev 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 parial success. This conversion keeps the bugs unchanged. Only compile tested. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Chas Williams <chas@cmf.nrl.navy.mil> Cc: netdev@vger.kernel.org --- This patch depends on an earlier idr changes and I think it would be best to route these together through -mm. Please holler if there's any objection. Thanks. drivers/atm/nicstar.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c index 628787e..7fd6834 100644 --- a/drivers/atm/nicstar.c +++ b/drivers/atm/nicstar.c @@ -1026,24 +1026,21 @@ 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); + if (!id1) { + 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) { + 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)) ; -- 1.8.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 09/62] atm/nicstar: convert to idr_alloc() 2013-02-03 1:20 ` [PATCH 09/62] atm/nicstar: convert to idr_alloc() Tejun Heo @ 2013-02-04 14:04 ` chas williams - CONTRACTOR 2013-02-04 17:06 ` Tejun Heo 2013-02-04 18:37 ` [PATCH v3 " Tejun Heo 1 sibling, 1 reply; 5+ messages in thread From: chas williams - CONTRACTOR @ 2013-02-04 14:04 UTC (permalink / raw) To: Tejun Heo Cc: akpm, linux-kernel, rusty, bfields, skinsbursky, ebiederm, jmorris, axboe, netdev I don't quite understand your comment. idr_pre_get() returns 0 in the case of failure. On Sat, 2 Feb 2013 17:20:10 -0800 Tejun Heo <tj@kernel.org> wrote: > 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 parial success. This > conversion keeps the bugs unchanged. > > Only compile tested. > > Signed-off-by: Tejun Heo <tj@kernel.org> > Cc: Chas Williams <chas@cmf.nrl.navy.mil> > Cc: netdev@vger.kernel.org > --- > This patch depends on an earlier idr changes and I think it would be > best to route these together through -mm. Please holler if there's > any objection. Thanks. > > drivers/atm/nicstar.c | 27 ++++++++++++--------------- > 1 file changed, 12 insertions(+), 15 deletions(-) > > diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c > index 628787e..7fd6834 100644 > --- a/drivers/atm/nicstar.c > +++ b/drivers/atm/nicstar.c > @@ -1026,24 +1026,21 @@ 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); > + if (!id1) { > + 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) { > + 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)) ; ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 09/62] atm/nicstar: convert to idr_alloc() 2013-02-04 14:04 ` chas williams - CONTRACTOR @ 2013-02-04 17:06 ` Tejun Heo 2013-02-04 18:06 ` chas williams - CONTRACTOR 0 siblings, 1 reply; 5+ messages in thread From: Tejun Heo @ 2013-02-04 17:06 UTC (permalink / raw) To: chas williams - CONTRACTOR Cc: akpm, linux-kernel, rusty, bfields, skinsbursky, ebiederm, jmorris, axboe, netdev Hello, Chas. On Mon, Feb 04, 2013 at 09:04:10AM -0500, chas williams - CONTRACTOR wrote: > I don't quite understand your comment. idr_pre_get() returns 0 in the > case of failure. So, if you do the following, int id1 = 0, id2 = 0; 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); if (err) goto out; You have no way of telling whether id1/2 are allocated or not. 0 is the special "not allocated" value but it also is a valid ID. The error path should be freeing id1/2 if either of them has been allocated but it doesn't and can't with 0 as the non-allocated value. Thanks. -- tejun ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 09/62] atm/nicstar: convert to idr_alloc() 2013-02-04 17:06 ` Tejun Heo @ 2013-02-04 18:06 ` chas williams - CONTRACTOR 0 siblings, 0 replies; 5+ messages in thread From: chas williams - CONTRACTOR @ 2013-02-04 18:06 UTC (permalink / raw) To: Tejun Heo Cc: akpm, linux-kernel, rusty, bfields, skinsbursky, ebiederm, jmorris, axboe, netdev On Mon, 4 Feb 2013 09:06:24 -0800 Tejun Heo <tj@kernel.org> wrote: > Hello, Chas. > > On Mon, Feb 04, 2013 at 09:04:10AM -0500, chas williams - CONTRACTOR wrote: > > I don't quite understand your comment. idr_pre_get() returns 0 in the > > case of failure. > > So, if you do the following, > > int id1 = 0, id2 = 0; > > 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); > if (err) > goto out; > > You have no way of telling whether id1/2 are allocated or not. 0 is > the special "not allocated" value but it also is a valid ID. The > error path should be freeing id1/2 if either of them has been > allocated but it doesn't and can't with 0 as the non-allocated value. yeah, i see now. it didn't understand what idr_get_new_above() was doing with the start id. i assumed that it would return something greater than the start id. i guess it never did return the starting id (atleast after some initial failure). additionally, yes, cleaning up if the second allocation failed was never done. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 09/62] atm/nicstar: convert to idr_alloc() 2013-02-03 1:20 ` [PATCH 09/62] atm/nicstar: convert to idr_alloc() Tejun Heo 2013-02-04 14:04 ` chas williams - CONTRACTOR @ 2013-02-04 18:37 ` Tejun Heo 1 sibling, 0 replies; 5+ messages in thread From: Tejun Heo @ 2013-02-04 18:37 UTC (permalink / raw) To: akpm Cc: linux-kernel, rusty, bfields, skinsbursky, ebiederm, jmorris, axboe, Chas Williams, netdev 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> Cc: netdev@vger.kernel.org --- drivers/atm/nicstar.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) --- a/drivers/atm/nicstar.c +++ b/drivers/atm/nicstar.c @@ -949,11 +949,10 @@ 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, 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, 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); - 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); ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-02-04 18:37 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <1359854463-2538-1-git-send-email-tj@kernel.org> 2013-02-03 1:20 ` [PATCH 09/62] atm/nicstar: convert to idr_alloc() Tejun Heo 2013-02-04 14:04 ` chas williams - CONTRACTOR 2013-02-04 17:06 ` Tejun Heo 2013-02-04 18:06 ` chas williams - CONTRACTOR 2013-02-04 18:37 ` [PATCH v3 " Tejun Heo
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).