public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Trivial patch against mempool
@ 2002-02-22 20:28 Balbir Singh
  2002-02-22 21:40 ` Marcus Alanen
  2002-02-23  0:02 ` Benjamin LaHaise
  0 siblings, 2 replies; 5+ messages in thread
From: Balbir Singh @ 2002-02-22 20:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: balbir_soni

Check if the alloc_fn and free_fn are not NULL. The caller generally
ensures that alloc_fn and free_fn are valid. It would not harm
to check. This makes the checking in mempool_create() more complete.


--- mempool.c.org       Fri Feb 22 12:00:58 2002
+++ mempool.c   Fri Feb 22 12:01:13 2002
@@ -35,7 +35,7 @@
        int i;

        pool = kmalloc(sizeof(*pool), GFP_KERNEL);
-       if (!pool)
+       if (!pool || !alloc_fn || !free_fn)
                return NULL;
        memset(pool, 0, sizeof(*pool));


Enjoy,
Balbir

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Trivial patch against mempool
  2002-02-22 20:28 [PATCH] Trivial patch against mempool Balbir Singh
@ 2002-02-22 21:40 ` Marcus Alanen
  2002-02-23  0:02 ` Benjamin LaHaise
  1 sibling, 0 replies; 5+ messages in thread
From: Marcus Alanen @ 2002-02-22 21:40 UTC (permalink / raw)
  To: balbir_soni, linux-kernel

>Check if the alloc_fn and free_fn are not NULL. The caller generally
>ensures that alloc_fn and free_fn are valid. It would not harm
>to check. This makes the checking in mempool_create() more complete.
>
>
>--- mempool.c.org       Fri Feb 22 12:00:58 2002
>+++ mempool.c   Fri Feb 22 12:01:13 2002
>@@ -35,7 +35,7 @@
>        int i;
>
>        pool = kmalloc(sizeof(*pool), GFP_KERNEL);
>-       if (!pool)
>+       if (!pool || !alloc_fn || !free_fn)
>                return NULL;
>        memset(pool, 0, sizeof(*pool));
>

A successful allocation with alloc_fn or free_fn equal to NULL
would return NULL, without freeing pool. => This check would
leak memory? Wouldn't it be better to check for !alloc_fn || !free_fn
before the kmalloc()


-- 
Marcus Alanen
maalanen@abo.fi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Trivial patch against mempool
@ 2002-02-22 21:59 Balbir Singh
  0 siblings, 0 replies; 5+ messages in thread
From: Balbir Singh @ 2002-02-22 21:59 UTC (permalink / raw)
  To: marcus, linux-kernel


You are absoultely correct. The correct patch is

--- mempool.c.org       Fri Feb 22 12:00:58 2002
+++ mempool.c   Fri Feb 22 15:01:02 2002
@@ -34,6 +34,9 @@
        mempool_t *pool;
        int i;

+       if (!alloc_fn || !free_fn)
+               return NULL;
+
        pool = kmalloc(sizeof(*pool), GFP_KERNEL);
        if (!pool)
                return NULL;

Balbir Singh.


>From: Marcus Alanen <marcus@infa.abo.fi>
>To: balbir_soni@hotmail.com, linux-kernel@vger.kernel.org
>Subject: Re: [PATCH] Trivial patch against mempool
>Date: Fri, 22 Feb 2002 23:40:43 +0200
>
> >Check if the alloc_fn and free_fn are not NULL. The caller generally
> >ensures that alloc_fn and free_fn are valid. It would not harm
> >to check. This makes the checking in mempool_create() more complete.
> >
> >
> >--- mempool.c.org       Fri Feb 22 12:00:58 2002
> >+++ mempool.c   Fri Feb 22 12:01:13 2002
> >@@ -35,7 +35,7 @@
> >        int i;
> >
> >        pool = kmalloc(sizeof(*pool), GFP_KERNEL);
> >-       if (!pool)
> >+       if (!pool || !alloc_fn || !free_fn)
> >                return NULL;
> >        memset(pool, 0, sizeof(*pool));
> >
>
>A successful allocation with alloc_fn or free_fn equal to NULL
>would return NULL, without freeing pool. => This check would
>leak memory? Wouldn't it be better to check for !alloc_fn || !free_fn
>before the kmalloc()
>
>
>--
>Marcus Alanen
>maalanen@abo.fi




_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Trivial patch against mempool
  2002-02-22 20:28 [PATCH] Trivial patch against mempool Balbir Singh
  2002-02-22 21:40 ` Marcus Alanen
@ 2002-02-23  0:02 ` Benjamin LaHaise
  1 sibling, 0 replies; 5+ messages in thread
From: Benjamin LaHaise @ 2002-02-23  0:02 UTC (permalink / raw)
  To: Balbir Singh; +Cc: linux-kernel

On Fri, Feb 22, 2002 at 12:28:14PM -0800, Balbir Singh wrote:
> Check if the alloc_fn and free_fn are not NULL. The caller generally
> ensures that alloc_fn and free_fn are valid. It would not harm
> to check. This makes the checking in mempool_create() more complete.

Rather than leak memory in that case, why not just BUG_ON null 
function pointers so that people know what code is at fault?

		-ben

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Trivial patch against mempool
@ 2002-02-23  0:37 Balbir Singh
  0 siblings, 0 replies; 5+ messages in thread
From: Balbir Singh @ 2002-02-23  0:37 UTC (permalink / raw)
  To: bcrl; +Cc: linux-kernel

That is a good suggestion too, I have redone the patch so
that the alloc_fn and free_fn are checked before calling
kmalloc(). I think the BUG_ON is also a good solution

I have the following now

1.
--- mempool.c.org       Fri Feb 22 12:00:58 2002
+++ mempool.c   Fri Feb 22 17:26:02 2002
@@ -34,6 +34,9 @@
        mempool_t *pool;
        int i;

+       BUG_ON(!alloc_fn);
+       BUG_ON(!free_fn);
+
        pool = kmalloc(sizeof(*pool), GFP_KERNEL);
        if (!pool)
                return NULL;

2.
--- mempool.c.org       Fri Feb 22 12:00:58 2002
+++ mempool.c   Fri Feb 22 17:38:52 2002
@@ -34,6 +34,8 @@
        mempool_t *pool;
        int i;

+       BUG_ON(!(alloc_fn && free_fn));
+
        pool = kmalloc(sizeof(*pool), GFP_KERNEL);
        if (!pool)
                return NULL;



I think (1) is more readable, what do you say?
Balbir

>From: Benjamin LaHaise <bcrl@redhat.com>
>To: Balbir Singh <balbir_soni@hotmail.com>
>CC: linux-kernel@vger.kernel.org
>Subject: Re: [PATCH] Trivial patch against mempool
>Date: Fri, 22 Feb 2002 19:02:56 -0500
>
>On Fri, Feb 22, 2002 at 12:28:14PM -0800, Balbir Singh wrote:
> > Check if the alloc_fn and free_fn are not NULL. The caller generally
> > ensures that alloc_fn and free_fn are valid. It would not harm
> > to check. This makes the checking in mempool_create() more complete.
>
>Rather than leak memory in that case, why not just BUG_ON null
>function pointers so that people know what code is at fault?
>
>		-ben




_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-02-23  0:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-02-22 20:28 [PATCH] Trivial patch against mempool Balbir Singh
2002-02-22 21:40 ` Marcus Alanen
2002-02-23  0:02 ` Benjamin LaHaise
  -- strict thread matches above, loose matches on Subject: below --
2002-02-22 21:59 Balbir Singh
2002-02-23  0:37 Balbir Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox