kexec: Avoid calculating array size twice
Subsystems (3)
PATCH 1/1 kexec: Avoid calculating array size twice
Avoid calculating array size twice in kexec_purgatory_setup_sechdrs(). Once using array_size(), and once open-coded.
Flagged by Coccinelle:
.../kexec_file.c:881:8-25: WARNING: array_size is already used (line 877) to compute the same size
No functional change intended.
Compile tested only.
--- kernel/kexec_file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/kexec_file.c +4 -3
@@ -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 ;
Quoted 6 lines · Simon Horman
Avoid calculating array size twice in
kexec_purgatory_setup_sechdrs(). Once usingarray_size(), and once open-coded.Flagged by Coccinelle:
.../kexec_file.c:881:8-25: WARNING:
array_sizeis already used (line 877) to compute the same size
Amazingly smart. Thanks.
Quoted 27 lines
No functional change intended.
Compile tested only.Signed-off-by Simon Horman <[email protected]>--- kernel/kexec_file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)kernel/kexec_file.c +1
-1@@ -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));
kernel/kexec_file.c static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, · line 885
Quoted 10 lines
kernel/kexec_file.c +3
-2+ 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 ;
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 11 lines · Baoquan He
Quoted 6 lines · Simon Horman
Avoid calculating array size twice in
kexec_purgatory_setup_sechdrs(). Once usingarray_size(), and once open-coded.Flagged by Coccinelle:
.../kexec_file.c:881:8-25: WARNING:
array_sizeis already used (line 877) to compute the same sizeAmazingly smart. Thanks.
Acked-by Baoquan He <[email protected]>
Just noticed Andrew has picked this one, please ignore this.
Quoted 36 lines
Quoted 36 lines
No functional change intended.
Compile tested only.Signed-off-by Simon Horman <[email protected]>--- kernel/kexec_file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)kernel/kexec_file.c +4
-3@@ -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;
Quoted 3 lines
kernel/kexec_file.c static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, · line 885
Quoted 2 lines
kernel/kexec_file.c +0
-0offset =0 ;
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec