diff mbox

[Xen-devel,V2,05/12] replace split_value() with truncate_string()

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

Commit Message

Roy Franz July 22, 2014, 12:43 a.m. UTC
Replace the split_value() function with a more generic string handling
function truncate_string().  split_value() used to update the multiboot
structures directly, and this has been moved to the call sites to allow
truncate_string() to be more generic.


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

Comments

Jan Beulich July 24, 2014, 7:19 a.m. UTC | #1
>>> On 22.07.14 at 02:43, <roy.franz@linaro.org> wrote:
> --- a/xen/arch/x86/efi/boot.c
> +++ b/xen/arch/x86/efi/boot.c
> @@ -466,7 +466,13 @@ static char *__init get_value(const struct file *cfg, const char *section,
>              break;
>          default:
>              if ( match && strncmp(ptr, item, ilen) == 0 && ptr[ilen] == '=' )
> -                return ptr + ilen + 1;
> +            {
> +                ptr += ilen + 1;
> +                /* strip off any leading spaces */

Coding style.

> +                while ( *ptr && isspace(*ptr) )
> +                    ptr++;
> +                return ptr;
> +            }

It's unclear how this whole hunk is related to the patch subject.

> @@ -489,14 +495,19 @@ bool_t __init load_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
>      return 0;
>  }
>  
> -static void __init split_value(char *s)
> +/* Truncate string at first space, and return pointer
> + * to remainder of string.
> + */

Coding style again.

> +char * __init truncate_string(char *s)

Non-static function without declaration in any header.

>  {
> -    while ( *s && isspace(*s) )
> -        ++s;
> -    place_string(&mb_modules[mbi.mods_count].string, s);
>      while ( *s && !isspace(*s) )
>          ++s;
> -    *s = 0;
> +    if (*s)
> +    {
> +        *s = 0;
> +        return(s + 1);
> +    }
> +    return(NULL);

None of the callers uses the return value - why is the function return
type not "void"? Also, if there is a reason, then no parentheses around
the return expression please.

> @@ -893,7 +904,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
>      }
>      if ( !name.s )
>          blexit(L"No Dom0 kernel image specified.");
> -    split_value(name.s);
> +    place_string(&mb_modules[mbi.mods_count].string, name.s);
> +    truncate_string(name.s);
>      load_ok = load_file(dir_handle, s2w(&name), &kernel);
>      efi_bs->FreePool(name.w);
>      if ( !load_ok )
> @@ -907,7 +919,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
>      name.s = get_value(&cfg, section.s, "ramdisk");
>      if ( name.s )
>      {
> -        split_value(name.s);
> +        place_string(&mb_modules[mbi.mods_count].string, name.s);
> +        truncate_string(name.s);
>          load_ok = load_file(dir_handle, s2w(&name), &ramdisk);
>          efi_bs->FreePool(name.w);
>          if ( !load_ok )
> @@ -920,7 +933,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
>      if ( name.s )
>      {
>          microcode_set_module(mbi.mods_count);
> -        split_value(name.s);
> +        place_string(&mb_modules[mbi.mods_count].string, name.s);
> +        truncate_string(name.s);
>          load_ok = load_file(dir_handle, s2w(&name), &ucode);
>          efi_bs->FreePool(name.w);
>          if ( !load_ok )
> @@ -930,7 +944,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
>      name.s = get_value(&cfg, section.s, "xsm");
>      if ( name.s )
>      {
> -        split_value(name.s);
> +        place_string(&mb_modules[mbi.mods_count].string, name.s);
> +        truncate_string(name.s);
>          load_ok = load_file(dir_handle, s2w(&name), &xsm);
>          efi_bs->FreePool(name.w);
>          if ( !load_ok )

Looking at all these I wonder why you didn't retain split_value() as a
simple wrapper.

Furthermore splitting out the place_string() doesn't seem very
efficient, as imo the goal ought to be for efi_start() to become
common code (or at least the module loading part of fit), i.e.
there's no win at all from the change you're doing here.

Jan
diff mbox

Patch

diff --git a/xen/arch/x86/efi/boot.c b/xen/arch/x86/efi/boot.c
index 17aaa67..546ff1c 100644
--- a/xen/arch/x86/efi/boot.c
+++ b/xen/arch/x86/efi/boot.c
@@ -466,7 +466,13 @@  static char *__init get_value(const struct file *cfg, const char *section,
             break;
         default:
             if ( match && strncmp(ptr, item, ilen) == 0 && ptr[ilen] == '=' )
-                return ptr + ilen + 1;
+            {
+                ptr += ilen + 1;
+                /* strip off any leading spaces */
+                while ( *ptr && isspace(*ptr) )
+                    ptr++;
+                return ptr;
+            }
             break;
         }
         ptr += strlen(ptr);
@@ -489,14 +495,19 @@  bool_t __init load_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
     return 0;
 }
 
-static void __init split_value(char *s)
+/* Truncate string at first space, and return pointer
+ * to remainder of string.
+ */
+char * __init truncate_string(char *s)
 {
-    while ( *s && isspace(*s) )
-        ++s;
-    place_string(&mb_modules[mbi.mods_count].string, s);
     while ( *s && !isspace(*s) )
         ++s;
-    *s = 0;
+    if (*s)
+    {
+        *s = 0;
+        return(s + 1);
+    }
+    return(NULL);
 }
 
 static void __init edd_put_string(u8 *dst, size_t n, const char *src)
@@ -893,7 +904,8 @@  efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     }
     if ( !name.s )
         blexit(L"No Dom0 kernel image specified.");
-    split_value(name.s);
+    place_string(&mb_modules[mbi.mods_count].string, name.s);
+    truncate_string(name.s);
     load_ok = load_file(dir_handle, s2w(&name), &kernel);
     efi_bs->FreePool(name.w);
     if ( !load_ok )
@@ -907,7 +919,8 @@  efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     name.s = get_value(&cfg, section.s, "ramdisk");
     if ( name.s )
     {
-        split_value(name.s);
+        place_string(&mb_modules[mbi.mods_count].string, name.s);
+        truncate_string(name.s);
         load_ok = load_file(dir_handle, s2w(&name), &ramdisk);
         efi_bs->FreePool(name.w);
         if ( !load_ok )
@@ -920,7 +933,8 @@  efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     if ( name.s )
     {
         microcode_set_module(mbi.mods_count);
-        split_value(name.s);
+        place_string(&mb_modules[mbi.mods_count].string, name.s);
+        truncate_string(name.s);
         load_ok = load_file(dir_handle, s2w(&name), &ucode);
         efi_bs->FreePool(name.w);
         if ( !load_ok )
@@ -930,7 +944,8 @@  efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     name.s = get_value(&cfg, section.s, "xsm");
     if ( name.s )
     {
-        split_value(name.s);
+        place_string(&mb_modules[mbi.mods_count].string, name.s);
+        truncate_string(name.s);
         load_ok = load_file(dir_handle, s2w(&name), &xsm);
         efi_bs->FreePool(name.w);
         if ( !load_ok )