Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1442418 > unrolled thread

[PATCH -next] module: use kmemdup rather than duplicating its implementation

Started byweiyj_lk@163.com
First post2016-07-13 15:00 +0200
Last post2016-07-19 01:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH -next] module: use kmemdup rather than duplicating its implementation weiyj_lk@163.com - 2016-07-13 15:00 +0200
    Re: [PATCH -next] module: use kmemdup rather than duplicating its implementation Rusty Russell <rusty@rustcorp.com.au> - 2016-07-19 01:50 +0200

#1442418 — [PATCH -next] module: use kmemdup rather than duplicating its implementation

Fromweiyj_lk@163.com
Date2016-07-13 15:00 +0200
Subject[PATCH -next] module: use kmemdup rather than duplicating its implementation
Message-ID<rUrVD-3bS-11@gated-at.bofh.it>
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Use kmemdup rather than duplicating its implementation.

Generated by: scripts/coccinelle/api/memdup.cocci

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 kernel/module.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index beaebea..04de59f 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1994,21 +1994,20 @@ 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;

[toc] | [next] | [standalone]


#1445932

FromRusty Russell <rusty@rustcorp.com.au>
Date2016-07-19 01:50 +0200
Message-ID<rWqsq-4uI-7@gated-at.bofh.it>
In reply to#1442418
weiyj_lk@163.com writes:
> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>
> Use kmemdup rather than duplicating its implementation.
>
> Generated by: scripts/coccinelle/api/memdup.cocci
>
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Hi Wei!

        This code has been removed by other changes in modules-next,
so your very nice cleanup is no longer necessary.

Thanks!
Rusty.

> ---
>  kernel/module.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/module.c b/kernel/module.c
> index beaebea..04de59f 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -1994,21 +1994,20 @@ 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;

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web