From 922d29ee490137791794380e2029b6c6ac57d066 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Mon, 15 Nov 2021 09:54:10 +0100 Subject: [PATCH] zdump: dfi_elf_init: introduce temporary variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce variable `phdrs` and shrink the scope of `phdr`. This removes duplicated code `&phdr[i]` and makes the code easier to read. While at it, constify the parameter of `pt_notes_add`. Signed-off-by: Marc Hartmayer Reviewed-by: Alexander Egorenkov Reviewed-by: Steffen Eiden Signed-off-by: Jan Höppner --- zdump/dfi_elf.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/zdump/dfi_elf.c b/zdump/dfi_elf.c index d3d77340..33215485 100644 --- a/zdump/dfi_elf.c +++ b/zdump/dfi_elf.c @@ -217,7 +217,7 @@ static int nt_s390_vxrs_high_read(struct dfi_cpu *cpu, Elf64_Nhdr *note) /* * Add all notes for notes phdr */ -static int pt_notes_add(Elf64_Phdr *phdr) +static int pt_notes_add(const Elf64_Phdr *phdr) { struct dfi_cpu *cpu_current = NULL; u64 notes_start_off; @@ -295,7 +295,7 @@ static int check_elf_hdr(const Elf64_Ehdr *ehdr) static int dfi_elf_init(void) { unsigned int phnum, i; - Elf64_Phdr *phdr; + Elf64_Phdr *phdrs; Elf64_Ehdr ehdr; util_log_print(UTIL_LOG_DEBUG, "DFI ELF initialization\n"); @@ -310,21 +310,22 @@ static int dfi_elf_init(void) dfi_arch_set(DFI_ARCH_64); dfi_cpu_info_init(DFI_CPU_CONTENT_ALL); - phdr = read_elf_phdrs(g.fh, &ehdr, &phnum); + phdrs = read_elf_phdrs(g.fh, &ehdr, &phnum); util_log_print(UTIL_LOG_DEBUG, "DFI ELF e_phnum %u\n", phnum); for (i = 0; i < phnum; i++) { - util_log_print(UTIL_LOG_DEBUG, "DFI ELF p_type[%d] 0x%lx\n", - i, phdr[i].p_type); - switch (phdr[i].p_type) { + const Elf64_Phdr *phdr = &phdrs[i]; + + util_log_print(UTIL_LOG_DEBUG, "DFI ELF p_type[%d] 0x%lx\n", i, phdr->p_type); + switch (phdr->p_type) { case PT_LOAD: - if (pt_load_add(&phdr[i])) { - free(phdr); + if (pt_load_add(phdr)) { + free(phdrs); return -EINVAL; } break; case PT_NOTE: - if (pt_notes_add(&phdr[i])) { - free(phdr); + if (pt_notes_add(phdr)) { + free(phdrs); return -EINVAL; } break; @@ -332,7 +333,7 @@ static int dfi_elf_init(void) break; } } - free(phdr); + free(phdrs); dfi_attr_version_set(ehdr.e_ident[EI_VERSION]); return 0;