When testing the UEFI LocateHandle() function, the BufferSize argument is
erroneously computed with a count from three test steps before, leading to
an incorrect input buffer size.

Also, while the buffer size returned by LocateHandle() is correctly
converted to a count during a subsequent comparison, it is incorrectly
passed "as is" as a count to later calls to find_in_buffer().

Finally, the variables usage during this test step is misleading, as the
`buffer_size' variable is used to hold a count, and the `count' variable is
used to hold a buffer size.

Fix all those issues at once, and remove also one copy to buffer_size,
which has now become unnecessary.

Signed-off-by: Vincent Stehlé <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Tom Rini <[email protected]>
---
 lib/efi_selftest/efi_selftest_manageprotocols.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/efi_selftest/efi_selftest_manageprotocols.c 
b/lib/efi_selftest/efi_selftest_manageprotocols.c
index 7fe7b285011..f07ff256ce1 100644
--- a/lib/efi_selftest/efi_selftest_manageprotocols.c
+++ b/lib/efi_selftest/efi_selftest_manageprotocols.c
@@ -170,7 +170,6 @@ static int execute(void)
                efi_st_error("LocateHandleBuffer with AllHandles failed\n");
                return EFI_ST_FAILURE;
        }
-       buffer_size = count;
        ret = find_in_buffer(handle1, count, buffer);
        if (ret != EFI_SUCCESS) {
                efi_st_error("LocateHandleBuffer failed to locate new 
handle\n");
@@ -245,14 +244,15 @@ static int execute(void)
        /*
         * Test LocateHandle with ByProtocol
         */
-       count = buffer_size * sizeof(efi_handle_t);
+       buffer_size = count * sizeof(efi_handle_t);
        ret = boottime->locate_handle(BY_PROTOCOL, &guid1, NULL,
-                                     &count, buffer);
+                                     &buffer_size, buffer);
        if (ret != EFI_SUCCESS) {
                efi_st_error("LocateHandle with ByProtocol failed\n");
                return EFI_ST_FAILURE;
        }
-       if (count / sizeof(efi_handle_t) != 2) {
+       count = buffer_size / sizeof(efi_handle_t);
+       if (count != 2) {
                efi_st_error("LocateHandle failed to locate new handles\n");
                return EFI_ST_FAILURE;
        }
-- 
2.51.0

Reply via email to