History

kernel/kexec_file.c: remove unneeded variables in kexec_purgatory_setup_sechdrs

The main loop currently uses quite a lot of variables to update the section headers. Some of them are unnecessary. So clean them up a little.

Philipp Rudo committed 8 years ago

Commit 620f6971 parent f1b1cca1 file · +12 −22Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/kexec_file.c+12−22
@@ -785,12 +785,8 @@ out: · 784 unmodified lines
785785 static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi,
786786 struct kexec_buf *kbuf)
787787 {
788− unsigned long curr_load_addr;
789− unsigned long load_addr;
790788 unsigned long bss_addr;
791789 unsigned long offset;
792− unsigned char *buf_addr;
793− unsigned char *src;
794790 Elf_Shdr *sechdrs;
795791 int i;
796792
@@ -823,20 +819,18 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, · 26 unmodified lines
823819 sechdrs[i].sh_offset;
824820 }
825821
826− /* Load SHF_ALLOC sections */
827− buf_addr = kbuf->buffer;
828− load_addr = curr_load_addr = kbuf->mem;
829− bss_addr = load_addr + kbuf->bufsz;
822+ offset = 0;
823+ bss_addr = kbuf->mem + kbuf->bufsz;
830824 kbuf->image->start = pi->ehdr->e_entry;
831825
832826 for (i = 0; i < pi->ehdr->e_shnum; i++) {
833827 unsigned long align;
828+ void *src, *dst;
834829
835830 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
836831 continue;
837832
838833 align = sechdrs[i].sh_addralign;
839−
840834 if (sechdrs[i].sh_type == SHT_NOBITS) {
841835 bss_addr = ALIGN(bss_addr, align);
842836 sechdrs[i].sh_addr = bss_addr;
@@ -844,31 +838,27 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, · 1 unmodified line
844838 continue;
845839 }
846840
847− curr_load_addr = ALIGN(curr_load_addr, align);
848− offset = curr_load_addr - load_addr;
849− /* We already modifed ->sh_offset to keep src addr */
850− src = (char *)sechdrs[i].sh_offset;
851− memcpy(buf_addr + offset, src, sechdrs[i].sh_size);
852−
841+ offset = ALIGN(offset, align);
853842 if (sechdrs[i].sh_flags & SHF_EXECINSTR &&
854843 pi->ehdr->e_entry >= sechdrs[i].sh_addr &&
855844 pi->ehdr->e_entry < (sechdrs[i].sh_addr
856845 + sechdrs[i].sh_size)) {
857846 kbuf->image->start -= sechdrs[i].sh_addr;
858− kbuf->image->start += curr_load_addr;
847+ kbuf->image->start += kbuf->mem + offset;
859848 }
860849
861− /* Store load address and source address of section */
862− sechdrs[i].sh_addr = curr_load_addr;
850+ src = (void *)sechdrs[i].sh_offset;
851+ dst = pi->purgatory_buf + offset;
852+ memcpy(dst, src, sechdrs[i].sh_size);
853+
854+ sechdrs[i].sh_addr = kbuf->mem + offset;
863855
864856 /*
865857 * This section got copied to temporary buffer. Update
866858 * ->sh_offset accordingly.
867859 */
868− sechdrs[i].sh_offset = (unsigned long)(buf_addr + offset);
869−
870− /* Advance to the next address */
871− curr_load_addr += sechdrs[i].sh_size;
860+ sechdrs[i].sh_offset = (unsigned long)dst;
861+ offset += sechdrs[i].sh_size;
872862 }
873863
874864 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t