Skip to contentSkip to conversation

use qemu_malloc and friends consistently

PATCH [email protected] 2 participants 2 messages Jun 1, 2009 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 6 lines · ----- "Jamie Lokier
Quoted 4 lines · [email protected] wrote:

Hi Kevin,

Thanks for pointing this. I guess it just sounds strange to me that somebody would want to alloc 0 bytes. But why not ...

Quoted 7 lines

Something that nobody pointed out is that sometimes you can have zero-length structures these days. E.g. if you have a struct containing a few spinlocks in the Linux kernel, it will be zero length
when built on UP targets. I doubt if QEMU has any such structures, but it's the sort of thing that shouldn't break qemu_malloc(sizeof(some_type)).

This is true but the kernel API is also making a clear distinction between the NULL returned value for allocation error and the specific ZERO_SIZE_PTR value returned for kmalloc(0, XXX). Things don't get mixed ...

JC

Quoted 1 line

-- Jamie

#2 lore raw
Quoted 17 lines · [email protected] wrote:
Quoted 6 lines · ----- "Jamie Lokier
Quoted 4 lines · [email protected] wrote:

Hi Kevin,

Thanks for pointing this. I guess it just sounds strange to me that somebody would want to alloc 0 bytes. But why not ...

Quoted 7 lines

Something that nobody pointed out is that sometimes you can have zero-length structures these days. E.g. if you have a struct containing a few spinlocks in the Linux kernel, it will be zero length
when built on UP targets. I doubt if QEMU has any such structures, but it's the sort of thing that shouldn't break qemu_malloc(sizeof(some_type)).

Quoted 1 line

This is true but the kernel API is also making a clear distinction between the NULL returned value for allocation error and the specific ZERO_SIZE_PTR value returned for kmalloc(0, XXX). Things don't get mixed ...

Ooh, smart.

That crossed my mind for qemu_malloc() too: return (void*)16, will SEGFAULT just like NULL but is non-NULL.

-- Jamie