LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* kmalloc() with size zero
@ 2007-03-23 0:18 Stephane Eranian
2007-03-23 1:38 ` Jan Engelhardt
2007-03-23 15:12 ` Christoph Lameter
0 siblings, 2 replies; 7+ messages in thread
From: Stephane Eranian @ 2007-03-23 0:18 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm, ak
Hello,
I ran into an issue with perfmon where I ended up calling
kmalloc() with a size of zero. To my surprise, this did
not return NULL but a valid data address.
I am wondering if this is a property of kmalloc() or simply
a bug. It is the case that the __kmalloc() code does not
check for zero size.
Thanks,
--
-Stephane
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kmalloc() with size zero
2007-03-23 0:18 kmalloc() with size zero Stephane Eranian
@ 2007-03-23 1:38 ` Jan Engelhardt
2007-03-23 4:39 ` Vignesh Babu BM
2007-03-23 15:12 ` Christoph Lameter
1 sibling, 1 reply; 7+ messages in thread
From: Jan Engelhardt @ 2007-03-23 1:38 UTC (permalink / raw)
To: Stephane Eranian; +Cc: linux-kernel, akpm, ak
On Mar 22 2007 16:18, Stephane Eranian wrote:
>
>Hello,
>
>I ran into an issue with perfmon where I ended up calling
>kmalloc() with a size of zero. To my surprise, this did
>not return NULL but a valid data address.
>
>I am wondering if this is a property of kmalloc() or simply
>a bug. It is the case that the __kmalloc() code does not
>check for zero size.
I'd say "feature", glibc's malloc also returns an address on malloc(0).
Jan
--
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kmalloc() with size zero
2007-03-23 1:38 ` Jan Engelhardt
@ 2007-03-23 4:39 ` Vignesh Babu BM
2007-03-25 16:30 ` Folkert van Heusden
0 siblings, 1 reply; 7+ messages in thread
From: Vignesh Babu BM @ 2007-03-23 4:39 UTC (permalink / raw)
To: Stephane Eranian; +Cc: linux-kernel, akpm, ak, Jan Engelhardt
On Fri, 2007-03-23 at 07:08 +0530, Jan Engelhardt wrote:
>
> On Mar 22 2007 16:18, Stephane Eranian wrote:
> >
> I'd say "feature", glibc's malloc also returns an address on
> malloc(0).
>
This is implementation defined-the standard allows for return of either
null or an address.
>
> Jan
> --
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
>
--
Regards,
Vignesh Babu BM
_____________________________________________________________
"Why is it that every time I'm with you, makes me believe in magic?"
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kmalloc() with size zero
2007-03-23 4:39 ` Vignesh Babu BM
@ 2007-03-25 16:30 ` Folkert van Heusden
2007-03-26 8:09 ` Stephane Eranian
0 siblings, 1 reply; 7+ messages in thread
From: Folkert van Heusden @ 2007-03-25 16:30 UTC (permalink / raw)
To: Vignesh Babu BM; +Cc: Stephane Eranian, linux-kernel, akpm, ak, Jan Engelhardt
> > I'd say "feature", glibc's malloc also returns an address on
> > malloc(0).
> >
> This is implementation defined-the standard allows for return of either
> null or an address.
Entirely for entertainment: AIX (5.3) returns NULL, IRIX returns a valid
address.
Folkert van Heusden
--
MultiTail är en flexibel redskap för att fälja logfilar, utför av
commandoer, filtrera, ge färg, sammanfoga, o.s.v. följa.
http://www.vanheusden.com/multitail/
----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kmalloc() with size zero
2007-03-25 16:30 ` Folkert van Heusden
@ 2007-03-26 8:09 ` Stephane Eranian
2007-03-29 14:39 ` Bill Davidsen
0 siblings, 1 reply; 7+ messages in thread
From: Stephane Eranian @ 2007-03-26 8:09 UTC (permalink / raw)
To: Folkert van Heusden
Cc: Vignesh Babu BM, linux-kernel, akpm, ak, Jan Engelhardt
Hi,
On Sun, Mar 25, 2007 at 06:30:34PM +0200, Folkert van Heusden wrote:
> > > I'd say "feature", glibc's malloc also returns an address on
> > > malloc(0).
> > >
> > This is implementation defined-the standard allows for return of either
> > null or an address.
>
> Entirely for entertainment: AIX (5.3) returns NULL, IRIX returns a valid
> address.
>
That's interesting, so many different behaviors! Personally, I still prefer
when malloc(0) returns zero because it makes it easier to catch errors.
--
-Stephane
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kmalloc() with size zero
2007-03-26 8:09 ` Stephane Eranian
@ 2007-03-29 14:39 ` Bill Davidsen
0 siblings, 0 replies; 7+ messages in thread
From: Bill Davidsen @ 2007-03-29 14:39 UTC (permalink / raw)
To: eranian
Cc: Folkert van Heusden, Vignesh Babu BM, linux-kernel, akpm, ak,
Jan Engelhardt
Stephane Eranian wrote:
> Hi,
>
> On Sun, Mar 25, 2007 at 06:30:34PM +0200, Folkert van Heusden wrote:
>>>> I'd say "feature", glibc's malloc also returns an address on
>>>> malloc(0).
>>>>
>>> This is implementation defined-the standard allows for return of either
>>> null or an address.
>> Entirely for entertainment: AIX (5.3) returns NULL, IRIX returns a valid
>> address.
>>
> That's interesting, so many different behaviors! Personally, I still prefer
> when malloc(0) returns zero because it makes it easier to catch errors.
>
Exactly, the address returned is not really useful, the improved error
checking is useful.
--
Bill Davidsen <davidsen@tmr.com>
"We have more to fear from the bungling of the incompetent than from
the machinations of the wicked." - from Slashdot
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kmalloc() with size zero
2007-03-23 0:18 kmalloc() with size zero Stephane Eranian
2007-03-23 1:38 ` Jan Engelhardt
@ 2007-03-23 15:12 ` Christoph Lameter
1 sibling, 0 replies; 7+ messages in thread
From: Christoph Lameter @ 2007-03-23 15:12 UTC (permalink / raw)
To: Stephane Eranian; +Cc: linux-kernel, akpm, ak
On Thu, 22 Mar 2007, Stephane Eranian wrote:
> I ran into an issue with perfmon where I ended up calling
> kmalloc() with a size of zero. To my surprise, this did
> not return NULL but a valid data address.
>
> I am wondering if this is a property of kmalloc() or simply
> a bug. It is the case that the __kmalloc() code does not
> check for zero size.
Correct SLAB will give you the smallest possible allocation. I'd say these
calls should be fixed. SLUB does check for zero and will throw a stack
dump.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-03-29 14:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-23 0:18 kmalloc() with size zero Stephane Eranian
2007-03-23 1:38 ` Jan Engelhardt
2007-03-23 4:39 ` Vignesh Babu BM
2007-03-25 16:30 ` Folkert van Heusden
2007-03-26 8:09 ` Stephane Eranian
2007-03-29 14:39 ` Bill Davidsen
2007-03-23 15:12 ` Christoph Lameter
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).