netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/sched: act_pedit: Use kmemdup() to replace kmalloc + memcpy
@ 2023-06-09  7:01 Jiapeng Chong
  2023-06-09 12:30 ` Pedro Tammela
  2023-06-12  8:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Jiapeng Chong @ 2023-06-09  7:01 UTC (permalink / raw)
  To: jhs
  Cc: xiyou.wangcong, jiri, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, Jiapeng Chong, Abaci Robot

./net/sched/act_pedit.c:245:21-28: WARNING opportunity for kmemdup.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5478
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
 net/sched/act_pedit.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index fc945c7e4123..8c4e7fddddbf 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -242,14 +242,12 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
 	nparms->tcfp_flags = parm->flags;
 	nparms->tcfp_nkeys = parm->nkeys;
 
-	nparms->tcfp_keys = kmalloc(ksize, GFP_KERNEL);
+	nparms->tcfp_keys = kmemdup(parm->keys, ksize, GFP_KERNEL);
 	if (!nparms->tcfp_keys) {
 		ret = -ENOMEM;
 		goto put_chain;
 	}
 
-	memcpy(nparms->tcfp_keys, parm->keys, ksize);
-
 	for (i = 0; i < nparms->tcfp_nkeys; ++i) {
 		u32 offmask = nparms->tcfp_keys[i].offmask;
 		u32 cur = nparms->tcfp_keys[i].off;
-- 
2.20.1.7.g153144c


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/sched: act_pedit: Use kmemdup() to replace kmalloc + memcpy
  2023-06-09  7:01 [PATCH] net/sched: act_pedit: Use kmemdup() to replace kmalloc + memcpy Jiapeng Chong
@ 2023-06-09 12:30 ` Pedro Tammela
  2023-06-09 15:55   ` Jamal Hadi Salim
  2023-06-12  8:40 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Pedro Tammela @ 2023-06-09 12:30 UTC (permalink / raw)
  To: Jiapeng Chong, jhs
  Cc: xiyou.wangcong, jiri, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, Abaci Robot

On 09/06/2023 04:01, Jiapeng Chong wrote:
> ./net/sched/act_pedit.c:245:21-28: WARNING opportunity for kmemdup.
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5478
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>

LGTM,

Reviewed-by: Pedro Tammela <pctammela@mojatatu.com>

> ---
>   net/sched/act_pedit.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
> index fc945c7e4123..8c4e7fddddbf 100644
> --- a/net/sched/act_pedit.c
> +++ b/net/sched/act_pedit.c
> @@ -242,14 +242,12 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
>   	nparms->tcfp_flags = parm->flags;
>   	nparms->tcfp_nkeys = parm->nkeys;
>   
> -	nparms->tcfp_keys = kmalloc(ksize, GFP_KERNEL);
> +	nparms->tcfp_keys = kmemdup(parm->keys, ksize, GFP_KERNEL);
>   	if (!nparms->tcfp_keys) {
>   		ret = -ENOMEM;
>   		goto put_chain;
>   	}
>   
> -	memcpy(nparms->tcfp_keys, parm->keys, ksize);
> -
>   	for (i = 0; i < nparms->tcfp_nkeys; ++i) {
>   		u32 offmask = nparms->tcfp_keys[i].offmask;
>   		u32 cur = nparms->tcfp_keys[i].off;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/sched: act_pedit: Use kmemdup() to replace kmalloc + memcpy
  2023-06-09 12:30 ` Pedro Tammela
@ 2023-06-09 15:55   ` Jamal Hadi Salim
  0 siblings, 0 replies; 4+ messages in thread
From: Jamal Hadi Salim @ 2023-06-09 15:55 UTC (permalink / raw)
  To: Pedro Tammela
  Cc: Jiapeng Chong, xiyou.wangcong, jiri, davem, edumazet, kuba,
	pabeni, netdev, linux-kernel, Abaci Robot

On Fri, Jun 9, 2023 at 8:30 AM Pedro Tammela <pctammela@mojatatu.com> wrote:
>
> On 09/06/2023 04:01, Jiapeng Chong wrote:
> > ./net/sched/act_pedit.c:245:21-28: WARNING opportunity for kmemdup.
> >
> > Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> > Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5478
> > Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
>
> LGTM,
>
> Reviewed-by: Pedro Tammela <pctammela@mojatatu.com>

Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>

cheers,
jamal

> > ---
> >   net/sched/act_pedit.c | 4 +---
> >   1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
> > index fc945c7e4123..8c4e7fddddbf 100644
> > --- a/net/sched/act_pedit.c
> > +++ b/net/sched/act_pedit.c
> > @@ -242,14 +242,12 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
> >       nparms->tcfp_flags = parm->flags;
> >       nparms->tcfp_nkeys = parm->nkeys;
> >
> > -     nparms->tcfp_keys = kmalloc(ksize, GFP_KERNEL);
> > +     nparms->tcfp_keys = kmemdup(parm->keys, ksize, GFP_KERNEL);
> >       if (!nparms->tcfp_keys) {
> >               ret = -ENOMEM;
> >               goto put_chain;
> >       }
> >
> > -     memcpy(nparms->tcfp_keys, parm->keys, ksize);
> > -
> >       for (i = 0; i < nparms->tcfp_nkeys; ++i) {
> >               u32 offmask = nparms->tcfp_keys[i].offmask;
> >               u32 cur = nparms->tcfp_keys[i].off;
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/sched: act_pedit: Use kmemdup() to replace kmalloc + memcpy
  2023-06-09  7:01 [PATCH] net/sched: act_pedit: Use kmemdup() to replace kmalloc + memcpy Jiapeng Chong
  2023-06-09 12:30 ` Pedro Tammela
@ 2023-06-12  8:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-12  8:40 UTC (permalink / raw)
  To: Jiapeng Chong
  Cc: jhs, xiyou.wangcong, jiri, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, abaci

Hello:

This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Fri,  9 Jun 2023 15:01:17 +0800 you wrote:
> ./net/sched/act_pedit.c:245:21-28: WARNING opportunity for kmemdup.
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5478
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
>  net/sched/act_pedit.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Here is the summary with links:
  - net/sched: act_pedit: Use kmemdup() to replace kmalloc + memcpy
    https://git.kernel.org/netdev/net-next/c/26e35370b976

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-12  8:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09  7:01 [PATCH] net/sched: act_pedit: Use kmemdup() to replace kmalloc + memcpy Jiapeng Chong
2023-06-09 12:30 ` Pedro Tammela
2023-06-09 15:55   ` Jamal Hadi Salim
2023-06-12  8:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).