Skip to contentSkip to conversation

AcpiOsAllocate with zero argument

Devel Rudolf Marek 2 participants 3 messages Jul 27, 2016 – Jul 28, 2016 ACPI component architecture (acpica)

lore
Share & tools
lore

Rudolf Marek

author
#0 lore raw

Hi all,

I could not find in the "ACPICA Overview and Programmer Reference" any clues what to do if someone calls AcpiOsAllocate() with size of zero. I checked the Linux implementation and it just calls kmalloc() which after bit of googling seems to return non-NULL for this case. I also tried to walk through the ACPICA sources and it seems to me that at least on some places it looks like that it could be called with 0 (num_gpe * sizeof(something))
I also tried to look to the "osdeps" of what the UEFI or unix stub do, but they simply pass it on. I could not find what UEFI does with zero, I only know that malloc can either return NULL (and success) or return also non-null pointer.

What is the correct way to handle the zero size allocations? Return non-NULL ?

Thanks
Rudolf

#1 lore raw

Hi, Rudolf

Quoted 20 lines

From: Devel [mailto:devel-bounces(a)acpica.org] On Behalf Of Rudolf Marek
Subject: [Devel] AcpiOsAllocate with zero argument

Hi all,

I could not find in the "ACPICA Overview and Programmer Reference" any clues
what to do if someone calls AcpiOsAllocate() with size of zero. I checked the
Linux implementation and it just calls kmalloc() which after bit of googling seems to return non-NULL for this case. I also tried to walk through the ACPICA
sources and it seems to me that at least on some places it looks like that it could be called with 0 (num_gpe * sizeof(something))
I also tried to look to the "osdeps" of what the UEFI or unix stub do, but they
simply pass it on. I could not find what UEFI does with zero, I only know that malloc can either return NULL (and success) or return also non-null pointer.

Quoted 2 lines

What is the correct way to handle the zero size allocations? Return non- NULL ?

[Lv Zheng]
IMO, there is no strict rule against the returning value of AcpiOsAllocate().
But there is an implied rule against AcpiOsFree() (IMO, should be documented in ACPICA reference manual). That is:
If NULL is passed to AcpiOsFree(), program crash shouldn't be resulted.
For AcpiOsFree() implemented for UEFI, BS->FreePool() returns EFI_INVALID_PARAMETER.
So it is compliant to this rule.

However, if you can see practical issues around these 2 functions, please let us know. We should fix all kinds of such issues.

Thanks
Lv

author
#2 lore raw

Hi Lv,

Thanks for the quick response. I checked the Linux kmalloc() and also UEFI AllocatePool() and they accept the zero size. No NULL is returned.

Therefore I would like to ask if it can be documented in the Programming Manual that zero size should be OK and
non-NULL value should be returned. Otherwise, it may happen that if implementation of AcpiOsAllocate() returns NULL and maybe there is some check in the ACPICA code which will complain and break things.

As for the free() you mean that NULL should be ignored?

Thanks
Rudolf