Skip to content

Commit

Permalink
Improve handling of the EFI map types[] array.
Browse files Browse the repository at this point in the history
Use nitems(), do not assume EFI_MD_TYPE_ contiguous allocation, in
particular, switch to use designated array initializers.

Reviewed by:	jhb (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Approved by:	re (gjb)
  • Loading branch information
kostikbel committed Sep 8, 2018
1 parent 3efdd58 commit 7404ab5
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions sbin/sysctl/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,22 +690,22 @@ S_efi_map(size_t l2, void *p)
size_t efisz;
int ndesc, i;

static const char *types[] = {
"Reserved",
"LoaderCode",
"LoaderData",
"BootServicesCode",
"BootServicesData",
"RuntimeServicesCode",
"RuntimeServicesData",
"ConventionalMemory",
"UnusableMemory",
"ACPIReclaimMemory",
"ACPIMemoryNVS",
"MemoryMappedIO",
"MemoryMappedIOPortSpace",
"PalCode",
"PersistentMemory"
static const char * const types[] = {
[EFI_MD_TYPE_NULL] = "Reserved",
[EFI_MD_TYPE_CODE] = "LoaderCode",
[EFI_MD_TYPE_DATA] = "LoaderData",
[EFI_MD_TYPE_BS_CODE] = "BootServicesCode",
[EFI_MD_TYPE_BS_DATA] = "BootServicesData",
[EFI_MD_TYPE_RT_CODE] = "RuntimeServicesCode",
[EFI_MD_TYPE_RT_DATA] = "RuntimeServicesData",
[EFI_MD_TYPE_FREE] = "ConventionalMemory",
[EFI_MD_TYPE_BAD] = "UnusableMemory",
[EFI_MD_TYPE_RECLAIM] = "ACPIReclaimMemory",
[EFI_MD_TYPE_FIRMWARE] = "ACPIMemoryNVS",
[EFI_MD_TYPE_IOMEM] = "MemoryMappedIO",
[EFI_MD_TYPE_IOPORT] = "MemoryMappedIOPortSpace",
[EFI_MD_TYPE_PALCODE] = "PalCode",
[EFI_MD_TYPE_PERSISTENT] = "PersistentMemory",
};

/*
Expand Down Expand Up @@ -734,9 +734,10 @@ S_efi_map(size_t l2, void *p)

for (i = 0; i < ndesc; i++,
map = efi_next_descriptor(map, efihdr->descriptor_size)) {
if (map->md_type <= EFI_MD_TYPE_PERSISTENT)
type = NULL;
if (map->md_type < nitems(types))
type = types[map->md_type];
else
if (type == NULL)
type = "<INVALID>";
printf("\n%23s %012jx %12p %08jx ", type,
(uintmax_t)map->md_phys, map->md_virt,
Expand Down

0 comments on commit 7404ab5

Please sign in to comment.