Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e83dda06 authored by Al Stone's avatar Al Stone Committed by Rafael J. Wysocki
Browse files

ACPI: improve acpi_extract_package() utility



The current version requires one to know the size of the package
a priori; this is almost impossible if the package is composed of
strings of variable length.  This change allows the utility to
allocate a buffer of the proper size if asked.

Signed-off-by: default avatarAl Stone <al.stone@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 088f1fd2
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -169,12 +169,21 @@ acpi_extract_package(union acpi_object *package,
	/*
	 * Validate output buffer.
	 */
	if (buffer->length == ACPI_ALLOCATE_BUFFER) {
		buffer->pointer = ACPI_ALLOCATE(size_required);
		if (!buffer->pointer)
			return AE_NO_MEMORY;
		buffer->length = size_required;
		memset(buffer->pointer, 0, size_required);
	} else {
		if (buffer->length < size_required) {
			buffer->length = size_required;
			return AE_BUFFER_OVERFLOW;
	} else if (buffer->length != size_required || !buffer->pointer) {
		} else if (buffer->length != size_required ||
			   !buffer->pointer) {
			return AE_BAD_PARAMETER;
		}
	}

	head = buffer->pointer;
	tail = buffer->pointer + tail_offset;