提交 9be936f4 编写于 作者: Z zhong jiang 提交者: Jessica Yu

kernel/module: Use kmemdup to replace kmalloc+memcpy

we prefer to the kmemdup rather than kmalloc+memcpy. so just
replace them.
Signed-off-by: Nzhong jiang <zhongjiang@huawei.com>
Signed-off-by: NJessica Yu <jeyu@kernel.org>
上级 4d58e703
...@@ -2039,21 +2039,19 @@ static int copy_module_elf(struct module *mod, struct load_info *info) ...@@ -2039,21 +2039,19 @@ static int copy_module_elf(struct module *mod, struct load_info *info)
/* Elf section header table */ /* Elf section header table */
size = sizeof(*info->sechdrs) * info->hdr->e_shnum; 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) { if (mod->klp_info->sechdrs == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto free_info; goto free_info;
} }
memcpy(mod->klp_info->sechdrs, info->sechdrs, size);
/* Elf section name string table */ /* Elf section name string table */
size = info->sechdrs[info->hdr->e_shstrndx].sh_size; 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) { if (mod->klp_info->secstrings == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto free_sechdrs; goto free_sechdrs;
} }
memcpy(mod->klp_info->secstrings, info->secstrings, size);
/* Elf symbol section index */ /* Elf symbol section index */
symndx = info->index.sym; symndx = info->index.sym;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册