Merge tag 'mm-nonmm-stable-2023-06-24-19-23' of git://git.kernel.org/pub/scm/linux...
[sfrench/cifs-2.6.git] / kernel / kexec_file.c
index 69ee4a29136fc819b51e35dd21e6808eddbc9fca..881ba0d1714ccf9cf49c22fbb238784f91596658 100644 (file)
@@ -867,6 +867,7 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi,
 {
        unsigned long bss_addr;
        unsigned long offset;
+       size_t sechdrs_size;
        Elf_Shdr *sechdrs;
        int i;
 
@@ -874,11 +875,11 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi,
         * The section headers in kexec_purgatory are read-only. In order to
         * have them modifiable make a temporary copy.
         */
-       sechdrs = vzalloc(array_size(sizeof(Elf_Shdr), pi->ehdr->e_shnum));
+       sechdrs_size = array_size(sizeof(Elf_Shdr), pi->ehdr->e_shnum);
+       sechdrs = vzalloc(sechdrs_size);
        if (!sechdrs)
                return -ENOMEM;
-       memcpy(sechdrs, (void *)pi->ehdr + pi->ehdr->e_shoff,
-              pi->ehdr->e_shnum * sizeof(Elf_Shdr));
+       memcpy(sechdrs, (void *)pi->ehdr + pi->ehdr->e_shoff, sechdrs_size);
        pi->sechdrs = sechdrs;
 
        offset = 0;