diff mbox

[Xen-devel,V2,03/12] Refactor get_parent_handle for sharing

Message ID 1405989815-25236-4-git-send-email-roy.franz@linaro.org
State New
Headers show

Commit Message

Roy Franz July 22, 2014, 12:43 a.m. UTC
Refactor get_parent_handle() to return NULL on error rather than directly
exiting, as the exit cleanup code is arch specific.  Having the common code
reference the architecture specific code causes pre-linking to fail.

Signed-off-by: Roy Franz <roy.franz@linaro.org>
---
 xen/arch/x86/efi/boot.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

Comments

Jan Beulich July 23, 2014, 4:37 p.m. UTC | #1
>>> On 22.07.14 at 02:43, <roy.franz@linaro.org> wrote:
> Refactor get_parent_handle() to return NULL on error rather than directly
> exiting, as the exit cleanup code is arch specific.

Is it? Not at this point at least.

>  Having the common code
> reference the architecture specific code causes pre-linking to fail.

Which certainly could be addressed if you told us details.

> @@ -706,6 +720,9 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
>      /* Get the file system interface. */
>      dir_handle = get_parent_handle(loaded_image, &file_name);
>  
> +    if ( !dir_handle )

Please avoid the rather pointless blank line above the if().

> +        blexit(L"EFI get_parent_handle failed.");

And please don't issue meaningless messages - the called function
already prints messages on all failure paths.

Jan
diff mbox

Patch

diff --git a/xen/arch/x86/efi/boot.c b/xen/arch/x86/efi/boot.c
index 849dc2d..c0546ec 100644
--- a/xen/arch/x86/efi/boot.c
+++ b/xen/arch/x86/efi/boot.c
@@ -237,12 +237,18 @@  static EFI_FILE_HANDLE __init get_parent_handle(EFI_LOADED_IMAGE *loaded_image,
         ret = efi_bs->HandleProtocol(loaded_image->DeviceHandle,
                                      &fs_protocol, (void **)&fio);
         if ( EFI_ERROR(ret) )
-            PrintErrMesgExit(L"Couldn't obtain the File System Protocol Interface",
+        {
+            PrintErrMesg(L"Couldn't obtain the File System Protocol Interface",
                          ret);
+            return NULL;
+        }
         ret = fio->OpenVolume(fio, &dir_handle);
     } while ( ret == EFI_MEDIA_CHANGED );
     if ( ret != EFI_SUCCESS )
-        PrintErrMesgExit(L"OpenVolume failure", ret);
+    {
+        PrintErrMesg(L"OpenVolume failure", ret);
+        return NULL;
+    }
 
 #define buffer ((CHAR16 *)keyhandler_scratch)
 #define BUFFERSIZE sizeof(keyhandler_scratch)
@@ -254,7 +260,10 @@  static EFI_FILE_HANDLE __init get_parent_handle(EFI_LOADED_IMAGE *loaded_image,
 
         if ( DevicePathType(dp) != MEDIA_DEVICE_PATH ||
              DevicePathSubType(dp) != MEDIA_FILEPATH_DP )
-            blexit(L"Unsupported device path component");
+        {
+            PrintErr(L"Unsupported device path component");
+            return NULL;
+        }
 
         if ( *buffer )
         {
@@ -265,7 +274,8 @@  static EFI_FILE_HANDLE __init get_parent_handle(EFI_LOADED_IMAGE *loaded_image,
             if ( ret != EFI_SUCCESS )
             {
                 PrintErr(L"Open failed for ");
-                PrintErrMesgExit(buffer, ret);
+                PrintErrMesg(buffer, ret);
+                return NULL;
             }
             dir_handle->Close(dir_handle);
             dir_handle = new_handle;
@@ -273,7 +283,10 @@  static EFI_FILE_HANDLE __init get_parent_handle(EFI_LOADED_IMAGE *loaded_image,
         fp = (void *)dp;
         if ( BUFFERSIZE < DevicePathNodeLength(dp) -
                           sizeof(*dp) + sizeof(*buffer) )
-            blexit(L"Increase BUFFERSIZE");
+        {
+            PrintErr(L"Increase BUFFERSIZE");
+            return NULL;
+        }
         memcpy(buffer, fp->PathName, DevicePathNodeLength(dp) - sizeof(*dp));
         buffer[(DevicePathNodeLength(dp) - sizeof(*dp)) / sizeof(*buffer)] = 0;
     }
@@ -292,7 +305,8 @@  static EFI_FILE_HANDLE __init get_parent_handle(EFI_LOADED_IMAGE *loaded_image,
                                    EFI_FILE_MODE_READ, 0);
             if ( ret != EFI_SUCCESS ) {
                 PrintErr(L"Open failed for ");
-                PrintErrMesgExit(buffer, ret);
+                PrintErrMesg(buffer, ret);
+                return NULL;
             }
             dir_handle->Close(dir_handle);
             dir_handle = new_handle;
@@ -706,6 +720,9 @@  efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     /* Get the file system interface. */
     dir_handle = get_parent_handle(loaded_image, &file_name);
 
+    if ( !dir_handle )
+        blexit(L"EFI get_parent_handle failed.");
+
     argc = get_argv(0, NULL, loaded_image->LoadOptions,
                     loaded_image->LoadOptionsSize);
     if ( argc > 0 &&