diff mbox series

[v8,3/5] efi/boot.c: wrap PrintStr/PrintErr to allow const CHAR16* arguments

Message ID 20200930120011.1622924-4-hudson@trmm.net (mailing list archive)
State Superseded
Headers show
Series efi: Unified Xen hypervisor/kernel/initrd images | expand

Commit Message

Trammell Hudson Sept. 30, 2020, noon UTC
This patch wraps the EFI OutputString() method so that they can be
called with const arguments.  The OutputString method does not modify
its argument, although the prototype is missing const, so it is necssary
to cast away the const when calling it.

It also updates callers of PrintStr/PrintErr to remove unneeded un-const casts.

Signed-off-by: Trammell Hudson <hudson@trmm.net>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 xen/common/efi/boot.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

Comments

Jan Beulich Sept. 30, 2020, 12:15 p.m. UTC | #1
On 30.09.2020 14:00, Trammell Hudson wrote:
> This patch wraps the EFI OutputString() method so that they can be
> called with const arguments.  The OutputString method does not modify
> its argument, although the prototype is missing const, so it is necssary
> to cast away the const when calling it.
> 
> It also updates callers of PrintStr/PrintErr to remove unneeded un-const casts.
> 
> Signed-off-by: Trammell Hudson <hudson@trmm.net>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>

This one got committed earlier today, sadly ...

> --- a/xen/common/efi/boot.c
> +++ b/xen/common/efi/boot.c
> @@ -151,10 +151,17 @@ static struct file __initdata cfg;
>  static struct file __initdata kernel;
>  static struct file __initdata ramdisk;
>  static struct file __initdata xsm;
> -static CHAR16 __initdata newline[] = L"\r\n";
> +static const CHAR16 __initconst newline[] = L"\r\n";
>  
> -#define PrintStr(s) StdOut->OutputString(StdOut, s)
> -#define PrintErr(s) StdErr->OutputString(StdErr, s)
> +static void __init PrintStr(const CHAR16 *s)
> +{
> +    StdOut->OutputString(StdOut, (CHAR16 *)s );

... without me noticing the stray blank here and ...

> +}
> +
> +static void __init PrintErr(const CHAR16 *s)
> +{
> +    StdErr->OutputString(StdErr, (CHAR16 *)s );

... here.

> @@ -540,7 +547,7 @@ static char * __init split_string(char *s)
>      return NULL;
>  }
>  
> -static void __init handle_file_info(CHAR16 *name,
> +static void __init handle_file_info(const CHAR16 *name,
>                                      const struct file *file, const char *options)
>  {
>      if ( file == &cfg )

Obviously I had to drop this hunk, which should now be folded
into patch 2. (If no other need for a v9 arises, I'll try to
remember to do so while committing that one.)

Jan
Trammell Hudson Sept. 30, 2020, 12:33 p.m. UTC | #2
On Wednesday, September 30, 2020 8:15 AM, Jan Beulich <jbeulich@suse.com> wrote:
> On 30.09.2020 14:00, Trammell Hudson wrote:
> > This patch wraps the EFI OutputString() method so that they can be
> > called with const arguments. The OutputString method does not modify
> > its argument, although the prototype is missing const, so it is necssary
> > to cast away the const when calling it.
> > It also updates callers of PrintStr/PrintErr to remove unneeded un-const casts.
> > Signed-off-by: Trammell Hudson hudson@trmm.net
> > Reviewed-by: Jan Beulich jbeulich@suse.com
>
> This one got committed earlier today, sadly ...

Ah, I had missed it when I rebased onto upstream/master, instead
of upstream/staging.

> [...]
> > @@ -540,7 +547,7 @@ static char * __init split_string(char *s)
> > return NULL;
> > }
> > -static void __init handle_file_info(CHAR16 *name,
> > +static void __init handle_file_info(const CHAR16 *name,
> > const struct file *file, const char *options)
> > {
> > if ( file == &cfg )
>
> Obviously I had to drop this hunk, which should now be folded
> into patch 2. (If no other need for a v9 arises, I'll try to
> remember to do so while committing that one.)

I've squashed them in my tree in case there is a v9. Hopefully
it doesn't come to that...

--
Trammell
diff mbox series

Patch

diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 93cfeba7e1..bd629eb658 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -151,10 +151,17 @@  static struct file __initdata cfg;
 static struct file __initdata kernel;
 static struct file __initdata ramdisk;
 static struct file __initdata xsm;
-static CHAR16 __initdata newline[] = L"\r\n";
+static const CHAR16 __initconst newline[] = L"\r\n";
 
-#define PrintStr(s) StdOut->OutputString(StdOut, s)
-#define PrintErr(s) StdErr->OutputString(StdErr, s)
+static void __init PrintStr(const CHAR16 *s)
+{
+    StdOut->OutputString(StdOut, (CHAR16 *)s );
+}
+
+static void __init PrintErr(const CHAR16 *s)
+{
+    StdErr->OutputString(StdErr, (CHAR16 *)s );
+}
 
 /*
  * Include architecture specific implementation here, which references the
@@ -275,7 +282,7 @@  static bool __init match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2)
 void __init noreturn blexit(const CHAR16 *str)
 {
     if ( str )
-        PrintStr((CHAR16 *)str);
+        PrintStr(str);
     PrintStr(newline);
 
     if ( !efi_bs )
@@ -316,7 +323,7 @@  static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode)
     EFI_STATUS ErrIdx = ErrCode & ~EFI_ERROR_MASK;
 
     StdOut = StdErr;
-    PrintErr((CHAR16 *)mesg);
+    PrintErr(mesg);
     PrintErr(L": ");
 
     if( (ErrIdx < ARRAY_SIZE(ErrCodeToStr)) && ErrCodeToStr[ErrIdx] )
@@ -540,7 +547,7 @@  static char * __init split_string(char *s)
     return NULL;
 }
 
-static void __init handle_file_info(CHAR16 *name,
+static void __init handle_file_info(const CHAR16 *name,
                                     const struct file *file, const char *options)
 {
     if ( file == &cfg )
@@ -562,7 +569,7 @@  static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
     EFI_FILE_HANDLE FileHandle = NULL;
     UINT64 size;
     EFI_STATUS ret;
-    CHAR16 *what = NULL;
+    const CHAR16 *what = NULL;
 
     if ( !name )
         PrintErrMesg(L"No filename", EFI_OUT_OF_RESOURCES);