kernel/module: Use kmemdup to replace kmalloc+memcpy
PATCH 1/1 kernel/module: Use kmemdup to replace kmalloc+memcpy
we prefer to the kmemdup rather than kmalloc+memcpy. so just replace them.
Signed-off-by zhong jiang <[email protected]>
--- kernel/module.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
kernel/module.c +2 -4
@@ -2057,21 +2057,19 @@ static int copy_module_elf(struct module *mod, struct load_info *info)/* Elf section header table */ size =sizeof (*info->sechdrs) * info->hdr->e_shnum; - mod->klp_info->sechdrs =kmalloc (size,GFP_KERNEL ); + mod->klp_info->sechdrs =kmemdup (info->sechdrs, size,GFP_KERNEL );if (mod->klp_info->sechdrs ==NULL ) { ret = -ENOMEM ; goto free_info; } -memcpy (mod->klp_info->sechdrs, info->sechdrs, size);/* Elf section name string table */ size = info->sechdrs[info->hdr->e_shstrndx].sh_size; - mod->klp_info->secstrings =kmalloc (size,GFP_KERNEL ); + mod->klp_info->secstrings =kmemdup (info->secstrings, size,GFP_KERNEL );if (mod->klp_info->secstrings ==NULL ) { ret = -ENOMEM ; goto free_sechdrs; } -memcpy (mod->klp_info->secstrings, info->secstrings, size);/* Elf symbol section index */ symndx = info->index.sym;
Signature · 1 line
1.7.12.4
Jessica Yu
Applied+++ zhong jiang [01/08/18 00:56 +0800]:
Quoted 4 lines
we prefer to the kmemdup rather than kmalloc+memcpy. so just replace them.
Signed-off-by zhong jiang <[email protected]>
Applied, thanks.
Jessica
Quoted 35 lines
---
kernel/module.c| 6 ++----1 file changed, 2 insertions(+), 4 deletions(-)kernel/module.c +2
-4@@ -2057,21 +2057,19 @@ static int copy_module_elf(struct module *mod, struct load_info *info)/* Elf section header table */ size =sizeof (*info->sechdrs) * info->hdr->e_shnum; - mod->klp_info->sechdrs =kmalloc (size,GFP_KERNEL ); + mod->klp_info->sechdrs =kmemdup (info->sechdrs, size,GFP_KERNEL );if (mod->klp_info->sechdrs ==NULL ) { ret = -ENOMEM ; goto free_info; } -memcpy (mod->klp_info->sechdrs, info->sechdrs, size);/* Elf section name string table */ size = info->sechdrs[info->hdr->e_shstrndx].sh_size; - mod->klp_info->secstrings =kmalloc (size,GFP_KERNEL ); + mod->klp_info->secstrings =kmemdup (info->secstrings, size,GFP_KERNEL );if (mod->klp_info->secstrings ==NULL ) { ret = -ENOMEM ; goto free_sechdrs; } -memcpy (mod->klp_info->secstrings, info->secstrings, size);/* Elf symbol section index */ symndx = info->index.sym;Signature · 1 line
1.7.12.4