On 19.03.2024 21:58, Jason Andryuk wrote:
> --- a/xen/common/libelf/libelf-dominfo.c
> +++ b/xen/common/libelf/libelf-dominfo.c
> @@ -101,26 +101,30 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary 
> *elf,
>  /* *INDENT-OFF* */
>      static const struct {
>          const char *name;
> -        bool str;
> +        enum {
> +            ELFNOTE_INT,
> +            ELFNOTE_STRING,
> +            ELFNOTE_NAME,

This last on could do with a comment, as there are two possible (but
distinct) purposes: Notes where the mere presence matters vs ones where
printing of the value(s) would simply be cumbersome.

> +        } type;
>      } note_desc[] = {
> -        [XEN_ELFNOTE_ENTRY] = { "ENTRY", 0},
> -        [XEN_ELFNOTE_HYPERCALL_PAGE] = { "HYPERCALL_PAGE", 0},
> -        [XEN_ELFNOTE_VIRT_BASE] = { "VIRT_BASE", 0},
> -        [XEN_ELFNOTE_INIT_P2M] = { "INIT_P2M", 0},
> -        [XEN_ELFNOTE_PADDR_OFFSET] = { "PADDR_OFFSET", 0},
> -        [XEN_ELFNOTE_HV_START_LOW] = { "HV_START_LOW", 0},
> -        [XEN_ELFNOTE_XEN_VERSION] = { "XEN_VERSION", 1},
> -        [XEN_ELFNOTE_GUEST_OS] = { "GUEST_OS", 1},
> -        [XEN_ELFNOTE_GUEST_VERSION] = { "GUEST_VERSION", 1},
> -        [XEN_ELFNOTE_LOADER] = { "LOADER", 1},
> -        [XEN_ELFNOTE_PAE_MODE] = { "PAE_MODE", 1},
> -        [XEN_ELFNOTE_FEATURES] = { "FEATURES", 1},
> -        [XEN_ELFNOTE_SUPPORTED_FEATURES] = { "SUPPORTED_FEATURES", 0},
> -        [XEN_ELFNOTE_BSD_SYMTAB] = { "BSD_SYMTAB", 1},
> -        [XEN_ELFNOTE_L1_MFN_VALID] = { "L1_MFN_VALID", false },
> -        [XEN_ELFNOTE_SUSPEND_CANCEL] = { "SUSPEND_CANCEL", 0 },
> -        [XEN_ELFNOTE_MOD_START_PFN] = { "MOD_START_PFN", 0 },
> -        [XEN_ELFNOTE_PHYS32_ENTRY] = { "PHYS32_ENTRY", 0 },
> +        [XEN_ELFNOTE_ENTRY] = { "ENTRY", ELFNOTE_INT },
> +        [XEN_ELFNOTE_HYPERCALL_PAGE] = { "HYPERCALL_PAGE", ELFNOTE_INT },
> +        [XEN_ELFNOTE_VIRT_BASE] = { "VIRT_BASE", ELFNOTE_INT },
> +        [XEN_ELFNOTE_INIT_P2M] = { "INIT_P2M", ELFNOTE_INT },
> +        [XEN_ELFNOTE_PADDR_OFFSET] = { "PADDR_OFFSET", ELFNOTE_INT },
> +        [XEN_ELFNOTE_HV_START_LOW] = { "HV_START_LOW", ELFNOTE_INT },
> +        [XEN_ELFNOTE_XEN_VERSION] = { "XEN_VERSION", ELFNOTE_STRING },
> +        [XEN_ELFNOTE_GUEST_OS] = { "GUEST_OS", ELFNOTE_STRING },
> +        [XEN_ELFNOTE_GUEST_VERSION] = { "GUEST_VERSION", ELFNOTE_STRING },
> +        [XEN_ELFNOTE_LOADER] = { "LOADER", ELFNOTE_STRING },
> +        [XEN_ELFNOTE_PAE_MODE] = { "PAE_MODE", ELFNOTE_STRING },
> +        [XEN_ELFNOTE_FEATURES] = { "FEATURES", ELFNOTE_STRING },
> +        [XEN_ELFNOTE_SUPPORTED_FEATURES] = { "SUPPORTED_FEATURES", 
> ELFNOTE_INT },
> +        [XEN_ELFNOTE_BSD_SYMTAB] = { "BSD_SYMTAB", ELFNOTE_STRING },
> +        [XEN_ELFNOTE_L1_MFN_VALID] = { "L1_MFN_VALID", ELFNOTE_NAME },
> +        [XEN_ELFNOTE_SUSPEND_CANCEL] = { "SUSPEND_CANCEL", ELFNOTE_INT },
> +        [XEN_ELFNOTE_MOD_START_PFN] = { "MOD_START_PFN", ELFNOTE_INT },
> +        [XEN_ELFNOTE_PHYS32_ENTRY] = { "PHYS32_ENTRY", ELFNOTE_INT },
>      };
>  /* *INDENT-ON* */
>  
> @@ -136,7 +140,7 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary *elf,
>          return 0;
>      }
>  
> -    if ( note_desc[type].str )
> +    if ( note_desc[type].type == ELFNOTE_STRING )
>      {
>          str = elf_strval(elf, elf_note_desc(elf, note));
>          if (str == NULL)
> @@ -146,13 +150,17 @@ elf_errorstatus elf_xen_parse_note(struct elf_binary 
> *elf,
>          parms->elf_notes[type].type = XEN_ENT_STR;
>          parms->elf_notes[type].data.str = str;
>      }
> -    else
> +    else if ( note_desc[type].type == ELFNOTE_INT )
>      {
>          val = elf_note_numeric(elf, note);
>          elf_msg(elf, "ELF: note: %s = %#" PRIx64 "\n", note_desc[type].name, 
> val);
>          parms->elf_notes[type].type = XEN_ENT_LONG;
>          parms->elf_notes[type].data.num = val;
>      }
> +    else if ( note_desc[type].type == ELFNOTE_NAME )
> +    {
> +        elf_msg(elf, "ELF: note: %s\n", note_desc[type].name);
> +    }

Imo this would better be expressed as (default-less) switch() now. That
would also save me from commenting on the excess braces in the last
"else if". I guess I wouldn't mind making both adjustments while
committing, so long as you agree. With them in place
Reviewed-by: Jan Beulich <jbeul...@suse.com>

Jan

Reply via email to