public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: edk2-devel@ml01.01.org
Cc: Jaben Carsey <jaben.carsey@intel.com>,
	Ruiyu Ni <ruiyu.ni@intel.com>, Tapan Shah <tapandshah@hpe.com>
Subject: [PATCH 2/2] ShellPkg/UefiHandleParsingLib: fix retval for empty child controller array
Date: Thu,  8 Sep 2016 18:14:14 +0200	[thread overview]
Message-ID: <20160908161414.3143-3-lersek@redhat.com> (raw)
In-Reply-To: <20160908161414.3143-1-lersek@redhat.com>

The ParseHandleDatabaseForChildControllers() function intends to work like
this:

(1) It allocates a "HandleBufferForReturn" local array that's guaranteed
    to be big enough for all found handles,

(2) it collects the handles, both counting them in the (mandatory)
    "MatchingHandleCount" output parameter, and saving them in the local
    "HandleBufferForReturn" array,

(3) if the caller is not interested in the actual handles, then
    "HandleBufferForReturn" is released,

(4) if the caller is interested in the handles, and we've found some, then
    "HandleBufferForReturn" is passed out through the
    "MatchingHandleBuffer" output parameter,

(5) if the caller is interested in the actual handles, but we've found
    none, then the "MatchingHandleBuffer" output parameter is set to NULL.

The ASSERT() at the end of the function makes this clear, but the
implementation does not conform to (5). Fix it.

Cc: Jaben Carsey <jaben.carsey@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Tapan Shah <tapandshah@hpe.com>
Reported-by: Tapan Shah <tapandshah@hpe.com>
Ref: https://tianocore.acgmultimedia.com/show_bug.cgi?id=112
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
index e11a3ccceab3..695d090926e1 100644
--- a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
+++ b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
@@ -2799,17 +2799,24 @@ ParseHandleDatabaseForChildControllers(
 
     FreePool (ChildControllerHandleBuffer);
   }
 
   FreePool (DriverBindingHandleBuffer);
 
+  if (MatchingHandleBuffer == NULL || *MatchingHandleCount == 0) {
+    //
+    // The caller is not interested in the actual handles, or we've found none.
+    //
+    FreePool (HandleBufferForReturn);
+    HandleBufferForReturn = NULL;
+  }
+
   if (MatchingHandleBuffer != NULL) {
     *MatchingHandleBuffer = HandleBufferForReturn;
-  } else {
-    FreePool(HandleBufferForReturn);
   }
+
   ASSERT ((MatchingHandleBuffer == NULL) ||
           (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) ||
           (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL));
 
   return (EFI_SUCCESS);
 }
-- 
2.9.2



  parent reply	other threads:[~2016-09-08 16:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-08 16:14 [PATCH 0/2] ShellPkg: fix assertion failure encountered with "devtree" and "dh -d -v" Laszlo Ersek
2016-09-08 16:14 ` [PATCH 1/2] ShellPkg/UefiHandleParsingLib: fix IN/OUT notation in child ctrlr parsing Laszlo Ersek
2016-09-08 16:14 ` Laszlo Ersek [this message]
2016-09-08 16:37 ` [PATCH 0/2] ShellPkg: fix assertion failure encountered with "devtree" and "dh -d -v" Carsey, Jaben
2016-09-08 17:08 ` Shah, Tapan
2016-09-08 17:09 ` Shah, Tapan
2016-09-08 18:35   ` Laszlo Ersek
2016-09-08 18:46 ` Laszlo Ersek

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-list 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=20160908161414.3143-3-lersek@redhat.com \
    --to=devel@edk2.groups.io \
    /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