Skip to contentSkip to conversation

net/sched: act_pedit: Use kmemdup() to replace kmalloc + memcpy

PATCH Applied Jiapeng Chong 4 participants 4 messages Jun 9, 2023 – Jun 12, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/sched: act_pedit: Use kmemdup() to replace kmalloc + memcpy

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

---
 net/sched/act_pedit.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/sched/act_pedit.c +1 -3
index fc945c7e4123..8c4e7fddddbf 100644
@@ -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;
Signature · 1 line
2.20.1.7.g153144c
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jiapeng Chong

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

LGTM,

Quoted 24 lines
---
  net/sched/act_pedit.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
net/sched/act_pedit.c +1 -3
index fc945c7e4123..8c4e7fddddbf 100644
@@ -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;
maintainer Acked-by
#2 lore raw
Quoted 11 lines · Pedro Tammela
Quoted 5 lines · Jiapeng Chong

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

LGTM,

cheers,
jamal

Quoted 25 lines
Quoted 24 lines
---
  net/sched/act_pedit.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
net/sched/act_pedit.c +1 -3
index fc945c7e4123..8c4e7fddddbf 100644
@@ -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;
#3 lore raw
In reply to Jiapeng Chong
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 8 lines · On Fri, 9 Jun 2023 15:01:17 +0800 you wrote:

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

---
 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html