misc improvement of code
Subsystems (2)
cover misc improvement of code
Cc: Simon Horman <[email protected]>
To: [email protected]
Pingfan Liu (2):
arm64/crashdump-arm64: explicit type conversion to suppress compiler
warning
kexec/elf: assign one to align if sh_addralign equals zero
kexec/arch/arm64/crashdump-arm64.c | 2 +- kexec/kexec-elf-rel.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 arm64/crashdump-arm64: explicit type conversion to suppress compiler warning
elf_info.page_offset is 'unsigned long long', while get_page_offset() has the input param as a type of 'unsigned long *'. It demands explicit type casting to mute the compiler warning.
--- kexec/arch/arm64/crashdump-arm64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kexec/arch/arm64/crashdump-arm64.c +1 -1
@@ -182,7 +182,7 @@ int load_crashdump_segments(struct kexec_info *info)if (err)return EFAILED ; -get_page_offset (&elf_info.page_offset); +get_page_offset ((unsigned long *)&elf_info.page_offset);dbgprintf ("%s: page_offset: %016llx\n" , __func__, elf_info.page_offset);
Signature · 1 line
2.31.1
PATCH 2/2 kexec/elf: assign one to align if sh_addralign equals zero
In reply to Pingfan LiuAccording to ELF specification, if sh_addralign equals zero or one, then the section has no alignment requirement on the start address. (I.e. it can be aligned on 1 byte)
Since modern cpu asks the .text, .data, .bss to be aligned on the machine word boundary at least, so in elf_rel_load(), sh_addralign can not be zero, and
align = shdr->sh_addralign;
...
bufsz = _ALIGN(bufsz, align);
will not render a result of 'bufsz = 0'.
But it had better have a check on the case of 'sh_addralign == 0' regardless of the assumption of machine word alignment.
This patch has no functional change.
--- kexec/kexec-elf-rel.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
kexec/kexec-elf-rel.c +7 -3
@@ -168,6 +168,10 @@ int build_elf_rel_info(const char *buf, off_t len, struct mem_ehdr *ehdr,return 0 ; } +static unsigned long get_section_addralign (struct mem_shdr *shdr) +{ +return (shdr->sh_addralign ==0 ) ?1 : shdr->sh_addralign; +}int elf_rel_load (struct mem_ehdr *ehdr,struct kexec_info *info,unsigned long min,unsigned long max,int end)
@@ -219,7 +223,7 @@ int elf_rel_load(struct mem_ehdr *ehdr, struct kexec_info *info, }if (shdr->sh_type !=SHT_NOBITS ) {unsigned long align; - align = shdr->sh_addralign; + align =get_section_addralign (shdr);/* See if I need more alignment */ if (buf_align < align) { buf_align = align;
@@ -231,7 +235,7 @@ int elf_rel_load(struct mem_ehdr *ehdr, struct kexec_info *info, }else {unsigned long align; - align = shdr->sh_addralign; + align =get_section_addralign (shdr);/* See if I need more alignment */ if (bss_align < align) { bss_align = align;
@@ -265,7 +269,7 @@ int elf_rel_load(struct mem_ehdr *ehdr, struct kexec_info *info,if (!(shdr->sh_flags &SHF_ALLOC )) {continue ; } - align = shdr->sh_addralign; + align =get_section_addralign (shdr);if (shdr->sh_type !=SHT_NOBITS ) {unsigned long off;/* Adjust the address */
Signature · 1 line
2.31.1
Simon Horman
Appliedcover misc improvement of code
In reply to Pingfan LiuQuoted 4 lines · Pingfan Liu
Cc: Simon Horman <[email protected]>
To: kexec at lists.infradead.org
Quoted 8 lines
Pingfan Liu (2):
arm64/crashdump-arm64: explicit type conversion to suppress compiler
warning
kexec/elf: assign one to align ifsh_addralignequals zerokexec/arch/arm64/crashdump-arm64.c | 2 +- kexec/kexec-elf-rel.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-)
Thanks, applied.