diff options
author | Al Stone <ahs3@redhat.com> | 2013-10-09 16:21:10 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-10-10 16:31:21 -0400 |
commit | e83dda06242073b1c7f9a88f1001e32a4b9fcd1d (patch) | |
tree | cf75d28d881175bd8eb0c9b9c1f823984782d167 | |
parent | 088f1fd267c7f43b5d87850a0fa0c7e851ecae97 (diff) |
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: Al Stone <al.stone@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r-- | drivers/acpi/utils.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 552248b0005b..fc2cd3284080 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c | |||
@@ -169,11 +169,20 @@ acpi_extract_package(union acpi_object *package, | |||
169 | /* | 169 | /* |
170 | * Validate output buffer. | 170 | * Validate output buffer. |
171 | */ | 171 | */ |
172 | if (buffer->length < size_required) { | 172 | if (buffer->length == ACPI_ALLOCATE_BUFFER) { |
173 | buffer->pointer = ACPI_ALLOCATE(size_required); | ||
174 | if (!buffer->pointer) | ||
175 | return AE_NO_MEMORY; | ||
173 | buffer->length = size_required; | 176 | buffer->length = size_required; |
174 | return AE_BUFFER_OVERFLOW; | 177 | memset(buffer->pointer, 0, size_required); |
175 | } else if (buffer->length != size_required || !buffer->pointer) { | 178 | } else { |
176 | return AE_BAD_PARAMETER; | 179 | if (buffer->length < size_required) { |
180 | buffer->length = size_required; | ||
181 | return AE_BUFFER_OVERFLOW; | ||
182 | } else if (buffer->length != size_required || | ||
183 | !buffer->pointer) { | ||
184 | return AE_BAD_PARAMETER; | ||
185 | } | ||
177 | } | 186 | } |
178 | 187 | ||
179 | head = buffer->pointer; | 188 | head = buffer->pointer; |