2005-03-24 15:25:46

by Ed Cashin

[permalink] [raw]
Subject: [PATCH 2.6.11] aoe [5/12]: don't try to free null bufpool


don't try to free null bufpool

Signed-off-by: Ed L. Cashin <[email protected]>

diff -uprN a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
--- a/drivers/block/aoe/aoedev.c 2005-03-10 12:19:11.000000000 -0500
+++ b/drivers/block/aoe/aoedev.c 2005-03-10 12:19:25.000000000 -0500
@@ -146,7 +146,8 @@ aoedev_freedev(struct aoedev *d)
put_disk(d->gd);
}
kfree(d->frames);
- mempool_destroy(d->bufpool);
+ if (d->bufpool)
+ mempool_destroy(d->bufpool);
kfree(d);
}



--
Ed L. Cashin <[email protected]>


2005-03-24 15:58:22

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [PATCH 2.6.11] aoe [5/12]: don't try to free null bufpool

On Thu, 2005-03-24 at 07:17 -0800, [email protected] wrote:
> don't try to free null bufpool

in linux there is a "rule" that all memory free routines are supposed to
also accept NULL as argument, so I think this patch is not needed (and
even wrong)

2005-03-24 17:04:45

by Ed Cashin

[permalink] [raw]
Subject: Re: [PATCH 2.6.11] aoe [5/12]: don't try to free null bufpool

Arjan van de Ven <[email protected]> writes:

> On Thu, 2005-03-24 at 07:17 -0800, [email protected] wrote:
>> don't try to free null bufpool
>
> in linux there is a "rule" that all memory free routines are supposed to
> also accept NULL as argument, so I think this patch is not needed (and
> even wrong)
>

Hmm. The mm/mempool.c:mempool_destroy function immediately
dereferences the pointer passed to it:

void mempool_destroy(mempool_t *pool)
{
if (pool->curr_nr != pool->min_nr)
BUG(); /* There were outstanding elements */
free_pool(pool);
}

... so I'm not sure mempool_destroy fits the rule. Are you suggesting
that the patch should instead modify mempool_destroy?

--
Ed L Cashin <[email protected]>

2005-03-24 17:17:17

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [PATCH 2.6.11] aoe [5/12]: don't try to free null bufpool

On Thu, 2005-03-24 at 09:04 -0800, [email protected] wrote:
> Arjan van de Ven <[email protected]> writes:
>
> > On Thu, 2005-03-24 at 07:17 -0800, [email protected] wrote:
> >> don't try to free null bufpool
> >
> > in linux there is a "rule" that all memory free routines are supposed to
> > also accept NULL as argument, so I think this patch is not needed (and
> > even wrong)
> >
>
> Hmm. The mm/mempool.c:mempool_destroy function immediately
> dereferences the pointer passed to it:
>
> void mempool_destroy(mempool_t *pool)
> {
> if (pool->curr_nr != pool->min_nr)
> BUG(); /* There were outstanding elements */
> free_pool(pool);
> }
>
> ... so I'm not sure mempool_destroy fits the rule. Are you suggesting
> that the patch should instead modify mempool_destroy?

hmm perhaps... Jens?

2005-03-25 14:35:50

by Jesper Juhl

[permalink] [raw]
Subject: Re: [PATCH 2.6.11] aoe [5/12]: don't try to free null bufpool

On Thu, 24 Mar 2005, Arjan van de Ven wrote:

> On Thu, 2005-03-24 at 09:04 -0800, [email protected] wrote:
> > Arjan van de Ven <[email protected]> writes:
> >
> > > On Thu, 2005-03-24 at 07:17 -0800, [email protected] wrote:
> > >> don't try to free null bufpool
> > >
> > > in linux there is a "rule" that all memory free routines are supposed to
> > > also accept NULL as argument, so I think this patch is not needed (and
> > > even wrong)
> > >
> >
> > Hmm. The mm/mempool.c:mempool_destroy function immediately
> > dereferences the pointer passed to it:
> >
> > void mempool_destroy(mempool_t *pool)
> > {
> > if (pool->curr_nr != pool->min_nr)
> > BUG(); /* There were outstanding elements */
> > free_pool(pool);
> > }
> >
> > ... so I'm not sure mempool_destroy fits the rule. Are you suggesting
> > that the patch should instead modify mempool_destroy?
>
> hmm perhaps... Jens?
>

Having mempool_destroy() be the one that checks seems safer, then callers
won't forget to check - easier to just check in one place.
If that's what you want, then here's a patch. If this is acceptable I can
create another one that removes the (then pointless) NULL checks from all
callers - let me know if that's wanted.

Signed-off-by: Jesper Juhl <[email protected]>

--- linux-2.6.12-rc1-mm3-orig/mm/mempool.c 2005-03-21 23:12:43.000000000 +0100
+++ linux-2.6.12-rc1-mm3/mm/mempool.c 2005-03-25 15:34:04.000000000 +0100
@@ -176,6 +176,8 @@ EXPORT_SYMBOL(mempool_resize);
*/
void mempool_destroy(mempool_t *pool)
{
+ if (!pool)
+ return;
if (pool->curr_nr != pool->min_nr)
BUG(); /* There were outstanding elements */
free_pool(pool);


2005-03-29 12:35:15

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH 2.6.11] aoe [5/12]: don't try to free null bufpool

On Thu, Mar 24 2005, Arjan van de Ven wrote:
> On Thu, 2005-03-24 at 09:04 -0800, [email protected] wrote:
> > Arjan van de Ven <[email protected]> writes:
> >
> > > On Thu, 2005-03-24 at 07:17 -0800, [email protected] wrote:
> > >> don't try to free null bufpool
> > >
> > > in linux there is a "rule" that all memory free routines are supposed to
> > > also accept NULL as argument, so I think this patch is not needed (and
> > > even wrong)
> > >
> >
> > Hmm. The mm/mempool.c:mempool_destroy function immediately
> > dereferences the pointer passed to it:
> >
> > void mempool_destroy(mempool_t *pool)
> > {
> > if (pool->curr_nr != pool->min_nr)
> > BUG(); /* There were outstanding elements */
> > free_pool(pool);
> > }
> >
> > ... so I'm not sure mempool_destroy fits the rule. Are you suggesting
> > that the patch should instead modify mempool_destroy?
>
> hmm perhaps... Jens?

Not really my call, but I agree we should make mempool_destroy()
resilient against !pool to follow the path of least surprise.

--
Jens Axboe