linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: al.stone@linaro.org
To: linux-acpi@vger.kernel.org
Cc: linaro-acpi@lists.linaro.org, Al Stone <ahs3@redhat.com>,
	Al Stone <al.stone@linaro.org>
Subject: [PATCH] ACPI: improve acpi_extract_package() utility
Date: Wed,  9 Oct 2013 14:21:10 -0600	[thread overview]
Message-ID: <1381350070-13208-1-git-send-email-al.stone@linaro.org> (raw)

From: Al Stone <ahs3@redhat.com>

  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>
---
 drivers/acpi/utils.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 552248b..fc2cd32 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -169,11 +169,20 @@ acpi_extract_package(union acpi_object *package,
 	/*
 	 * Validate output buffer.
 	 */
-	if (buffer->length < size_required) {
+	if (buffer->length == ACPI_ALLOCATE_BUFFER) {
+		buffer->pointer = ACPI_ALLOCATE(size_required);
+		if (!buffer->pointer)
+			return AE_NO_MEMORY;
 		buffer->length = size_required;
-		return AE_BUFFER_OVERFLOW;
-	} else if (buffer->length != size_required || !buffer->pointer) {
-		return AE_BAD_PARAMETER;
+		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) {
+			return AE_BAD_PARAMETER;
+		}
 	}
 
 	head = buffer->pointer;
-- 
1.8.3.1


                 reply	other threads:[~2013-10-09 20:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1381350070-13208-1-git-send-email-al.stone@linaro.org \
    --to=al.stone@linaro.org \
    --cc=ahs3@redhat.com \
    --cc=linaro-acpi@lists.linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).