ACPICA: Optimize buffer allocation procedure
Eliminate duplicate code. Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Lin Ming <ming.m.lin@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
@@ -240,7 +240,7 @@ acpi_status
|
|||||||
acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
|
acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
|
||||||
acpi_size required_length)
|
acpi_size required_length)
|
||||||
{
|
{
|
||||||
acpi_status status = AE_OK;
|
acpi_size input_buffer_length;
|
||||||
|
|
||||||
/* Parameter validation */
|
/* Parameter validation */
|
||||||
|
|
||||||
@@ -248,55 +248,58 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
|
|||||||
return (AE_BAD_PARAMETER);
|
return (AE_BAD_PARAMETER);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (buffer->length) {
|
/*
|
||||||
|
* Buffer->Length is used as both an input and output parameter. Get the
|
||||||
|
* input actual length and set the output required buffer length.
|
||||||
|
*/
|
||||||
|
input_buffer_length = buffer->length;
|
||||||
|
buffer->length = required_length;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The input buffer length contains the actual buffer length, or the type
|
||||||
|
* of buffer to be allocated by this routine.
|
||||||
|
*/
|
||||||
|
switch (input_buffer_length) {
|
||||||
case ACPI_NO_BUFFER:
|
case ACPI_NO_BUFFER:
|
||||||
|
|
||||||
/* Set the exception and returned the required length */
|
/* Return the exception (and the required buffer length) */
|
||||||
|
|
||||||
status = AE_BUFFER_OVERFLOW;
|
return (AE_BUFFER_OVERFLOW);
|
||||||
break;
|
|
||||||
|
|
||||||
case ACPI_ALLOCATE_BUFFER:
|
case ACPI_ALLOCATE_BUFFER:
|
||||||
|
|
||||||
/* Allocate a new buffer */
|
/* Allocate a new buffer */
|
||||||
|
|
||||||
buffer->pointer = acpi_os_allocate(required_length);
|
buffer->pointer = acpi_os_allocate(required_length);
|
||||||
if (!buffer->pointer) {
|
|
||||||
return (AE_NO_MEMORY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clear the buffer */
|
|
||||||
|
|
||||||
ACPI_MEMSET(buffer->pointer, 0, required_length);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACPI_ALLOCATE_LOCAL_BUFFER:
|
case ACPI_ALLOCATE_LOCAL_BUFFER:
|
||||||
|
|
||||||
/* Allocate a new buffer with local interface to allow tracking */
|
/* Allocate a new buffer with local interface to allow tracking */
|
||||||
|
|
||||||
buffer->pointer = ACPI_ALLOCATE_ZEROED(required_length);
|
buffer->pointer = ACPI_ALLOCATE(required_length);
|
||||||
if (!buffer->pointer) {
|
|
||||||
return (AE_NO_MEMORY);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
/* Existing buffer: Validate the size of the buffer */
|
/* Existing buffer: Validate the size of the buffer */
|
||||||
|
|
||||||
if (buffer->length < required_length) {
|
if (input_buffer_length < required_length) {
|
||||||
status = AE_BUFFER_OVERFLOW;
|
return (AE_BUFFER_OVERFLOW);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the buffer */
|
/* Validate allocation from above or input buffer pointer */
|
||||||
|
|
||||||
|
if (!buffer->pointer) {
|
||||||
|
return (AE_NO_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Have a valid buffer, clear it */
|
||||||
|
|
||||||
ACPI_MEMSET(buffer->pointer, 0, required_length);
|
ACPI_MEMSET(buffer->pointer, 0, required_length);
|
||||||
break;
|
return (AE_OK);
|
||||||
}
|
|
||||||
|
|
||||||
buffer->length = required_length;
|
|
||||||
return (status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NOT_USED_BY_LINUX
|
#ifdef NOT_USED_BY_LINUX
|
||||||
|
Reference in New Issue
Block a user