* [PATCH 2/2] lib/btree: Fix possible NULL pointer dereference
@ 2010-05-12 21:20 Denis Kirjanov <kirjanov@gmail.com
2010-05-13 20:19 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Denis Kirjanov <kirjanov@gmail.com @ 2010-05-12 21:20 UTC (permalink / raw)
To: joern; +Cc: linux-kernel
mempool_alloc can return null in atomic case.
Signed-off-by: Denis Kirjanov <kirjanov@gmail.com>
---
diff --git a/lib/btree.c b/lib/btree.c
index 41859a8..542c904 100644
--- a/lib/btree.c
+++ b/lib/btree.c
@@ -95,7 +94,8 @@ static unsigned long *btree_node_alloc(struct btree_head *head, gfp_t gfp)
unsigned long *node;
node = mempool_alloc(head->mempool, gfp);
- memset(node, 0, NODESIZE);
+ if (likely(node))
+ memset(node, 0, NODESIZE);
return node;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] lib/btree: Fix possible NULL pointer dereference
2010-05-12 21:20 [PATCH 2/2] lib/btree: Fix possible NULL pointer dereference Denis Kirjanov <kirjanov@gmail.com
@ 2010-05-13 20:19 ` Andrew Morton
2010-05-14 17:41 ` Jörn Engel
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2010-05-13 20:19 UTC (permalink / raw)
To: kirjanov; +Cc: joern, linux-kernel
On Thu, 13 May 2010 01:20:27 +0400
"Denis Kirjanov <kirjanov@gmail.com" <kirjanov@gmail.com> wrote:
> mempool_alloc can return null in atomic case.
>
> Signed-off-by: Denis Kirjanov <kirjanov@gmail.com>
> ---
> diff --git a/lib/btree.c b/lib/btree.c
> index 41859a8..542c904 100644
> --- a/lib/btree.c
> +++ b/lib/btree.c
> @@ -95,7 +94,8 @@ static unsigned long *btree_node_alloc(struct btree_head *head, gfp_t gfp)
> unsigned long *node;
>
> node = mempool_alloc(head->mempool, gfp);
> - memset(node, 0, NODESIZE);
> + if (likely(node))
> + memset(node, 0, NODESIZE);
> return node;
> }
hm, why is btree.c using mempools? mempools are only appropriate when
it is known that objects will become available if the allocating task
simply waits for a while. Typically, things like BIOs and
request-structs. Simply waiting for the disk to complete some IO will
cause some objects to be returned to the mempool.
If waiting-and-doing-nothing fails to cause objects to be returned to
the pool then the mempool code can lock up.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] lib/btree: Fix possible NULL pointer dereference
2010-05-13 20:19 ` Andrew Morton
@ 2010-05-14 17:41 ` Jörn Engel
0 siblings, 0 replies; 3+ messages in thread
From: Jörn Engel @ 2010-05-14 17:41 UTC (permalink / raw)
To: Andrew Morton; +Cc: kirjanov, linux-kernel
On Thu, 13 May 2010 13:19:07 -0700, Andrew Morton wrote:
> On Thu, 13 May 2010 01:20:27 +0400
> "Denis Kirjanov <kirjanov@gmail.com" <kirjanov@gmail.com> wrote:
>
> > mempool_alloc can return null in atomic case.
> >
> > Signed-off-by: Denis Kirjanov <kirjanov@gmail.com>
> > ---
> > diff --git a/lib/btree.c b/lib/btree.c
> > index 41859a8..542c904 100644
> > --- a/lib/btree.c
> > +++ b/lib/btree.c
> > @@ -95,7 +94,8 @@ static unsigned long *btree_node_alloc(struct btree_head *head, gfp_t gfp)
> > unsigned long *node;
> >
> > node = mempool_alloc(head->mempool, gfp);
> > - memset(node, 0, NODESIZE);
> > + if (likely(node))
> > + memset(node, 0, NODESIZE);
> > return node;
> > }
>
> hm, why is btree.c using mempools? mempools are only appropriate when
> it is known that objects will become available if the allocating task
> simply waits for a while. Typically, things like BIOs and
> request-structs. Simply waiting for the disk to complete some IO will
> cause some objects to be returned to the mempool.
For the current caller (logfs), that is a fairly accurate description.
> If waiting-and-doing-nothing fails to cause objects to be returned to
> the pool then the mempool code can lock up.
True. And I am not 100% sure logfs is bug-free in that respect. One
item on my todo list is to add some sort of mempool_prefill() that
either ensures pool->curr_nr == pool->min_nr or returns -ENOMEM. That
would allow logfs start some writeback and wait for the flash, when
necessary.
Jörn
--
When in doubt, punt. When somebody actually complains, go back and fix it...
The 90% solution is a good thing.
-- Rob Landley
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-05-14 17:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-12 21:20 [PATCH 2/2] lib/btree: Fix possible NULL pointer dereference Denis Kirjanov <kirjanov@gmail.com
2010-05-13 20:19 ` Andrew Morton
2010-05-14 17:41 ` Jörn Engel
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).