Skip to content

Commit

Permalink
kernel/module: Use kmemdup to replace kmalloc+memcpy
Browse files Browse the repository at this point in the history
we prefer to the kmemdup rather than kmalloc+memcpy. so just
replace them.

Signed-off-by: zhong jiang <[email protected]>
Signed-off-by: Jessica Yu <[email protected]>
  • Loading branch information
xiongzhongjiang authored and Jessica Yu committed Aug 2, 2018
1 parent 4d58e70 commit 9be936f
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2039,21 +2039,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;
Expand Down

0 comments on commit 9be936f

Please sign in to comment.