Re: [trivial PATCH] efi/libstub: Reduce efi_printk object size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 4 May 2020 at 20:29, Joe Perches <joe@xxxxxxxxxxx> wrote:
>
> Use a few more common kernel styles.
>
> Trivially reduce efi_printk object size by using a dereference to
> a temporary instead of multiple dereferences of the same object.
>
> Use efi_printk(const char *str) and static or static const for its
> internal variables.
>
> Use the more common form of while instead of a for loop.
>
> Change efi_char16_printk argument to const.
>
> Signed-off-by: Joe Perches <joe@xxxxxxxxxxx>

Thanks Joe.


> ---
>  drivers/firmware/efi/libstub/efi-stub-helper.c | 16 ++++++++--------
>  drivers/firmware/efi/libstub/efistub.h         |  6 +++---
>  2 files changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
> index 1c92ac231f94..dfd72a4360ac 100644
> --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
> +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
> @@ -26,19 +26,19 @@ bool __pure __efi_soft_reserve_enabled(void)
>         return !efi_nosoftreserve;
>  }
>
> -void efi_printk(char *str)
> +void efi_printk(const char *str)
>  {
> -       char *s8;
> +       char s8;
>
> -       for (s8 = str; *s8; s8++) {
> -               efi_char16_t ch[2] = { 0 };
> +       while ((s8 = *str++)) {

I'm not sure I prefer the assignment-as-truth-value construct over the
original for () tbh

> +               static efi_char16_t ch[2] = {0, 0};
>

UEFI code could potentially be reentrant, so this should not be static.

> -               ch[0] = *s8;
> -               if (*s8 == '\n') {
> -                       efi_char16_t nl[2] = { '\r', 0 };
> +               if (s8 == '\n') {
> +                       static const efi_char16_t nl[2] = { '\r', 0 };
>                         efi_char16_printk(nl);

We cannot make this const, unfortunately (see below). But we can clean
this up by using L"\r" as the initializer.

>                 }
>
> +               ch[0] = s8;
>                 efi_char16_printk(ch);
>         }
>  }
> @@ -284,7 +284,7 @@ void *get_efi_config_table(efi_guid_t guid)
>         return NULL;
>  }
>
> -void efi_char16_printk(efi_char16_t *str)
> +void efi_char16_printk(const efi_char16_t *str)
>  {
>         efi_call_proto(efi_table_attr(efi_system_table, con_out),
>                        output_string, str);
> diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
> index 5ff63230a1f1..a03a92c665f0 100644
> --- a/drivers/firmware/efi/libstub/efistub.h
> +++ b/drivers/firmware/efi/libstub/efistub.h
> @@ -251,7 +251,7 @@ union efi_simple_text_output_protocol {
>         struct {
>                 void *reset;
>                 efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
> -                                                      efi_char16_t *);
> +                                                      const efi_char16_t *);

This prototype comes straight from the UEFI specification, and even
though it is dumb that they forgot about const-qualified pointers
entirely, I would prefer not to deviate from this.

>                 void *test_string;
>         };
>         struct {
> @@ -599,7 +599,7 @@ efi_status_t efi_exit_boot_services(void *handle,
>                                     void *priv,
>                                     efi_exit_boot_map_processing priv_func);
>
> -void efi_char16_printk(efi_char16_t *);
> +void efi_char16_printk(const efi_char16_t *str);
>
>  efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
>                                             unsigned long *new_fdt_addr,
> @@ -624,7 +624,7 @@ efi_status_t check_platform_features(void);
>
>  void *get_efi_config_table(efi_guid_t guid);
>
> -void efi_printk(char *str);
> +void efi_printk(const char *str);
>
>  void efi_free(unsigned long size, unsigned long addr);
>
>



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux