diff mbox series

net: dsa: felix: use kmemdup() to replace kmalloc + memcpy

Message ID 20211207064419.38632-1-hanyihao@vivo.com (mailing list archive)
State Accepted
Commit e44aecc709ad3945e152c120693127d468e6487c
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: felix: use kmemdup() to replace kmalloc + memcpy | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 25 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Yihao Han Dec. 7, 2021, 6:44 a.m. UTC
Fix following coccicheck warning:
/drivers/net/dsa/ocelot/felix_vsc9959.c:1627:13-20:
WARNING opportunity for kmemdup
/drivers/net/dsa/ocelot/felix_vsc9959.c:1506:16-23:
WARNING opportunity for kmemdup

Signed-off-by: Yihao Han <hanyihao@vivo.com>
---
 drivers/net/dsa/ocelot/felix_vsc9959.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Vladimir Oltean Dec. 7, 2021, 1:56 p.m. UTC | #1
On Mon, Dec 06, 2021 at 10:44:18PM -0800, Yihao Han wrote:
> Fix following coccicheck warning:
> /drivers/net/dsa/ocelot/felix_vsc9959.c:1627:13-20:
> WARNING opportunity for kmemdup
> /drivers/net/dsa/ocelot/felix_vsc9959.c:1506:16-23:
> WARNING opportunity for kmemdup
> 
> Signed-off-by: Yihao Han <hanyihao@vivo.com>
> ---

Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
patchwork-bot+netdevbpf@kernel.org Dec. 8, 2021, 6:10 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  6 Dec 2021 22:44:18 -0800 you wrote:
> Fix following coccicheck warning:
> /drivers/net/dsa/ocelot/felix_vsc9959.c:1627:13-20:
> WARNING opportunity for kmemdup
> /drivers/net/dsa/ocelot/felix_vsc9959.c:1506:16-23:
> WARNING opportunity for kmemdup
> 
> Signed-off-by: Yihao Han <hanyihao@vivo.com>
> 
> [...]

Here is the summary with links:
  - net: dsa: felix: use kmemdup() to replace kmalloc + memcpy
    https://git.kernel.org/netdev/net-next/c/e44aecc709ad

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c
index 9add86eda7e3..0076420308a7 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -1503,12 +1503,10 @@  static int vsc9959_stream_table_add(struct ocelot *ocelot,
 	struct felix_stream *stream_entry;
 	int ret;
 
-	stream_entry = kzalloc(sizeof(*stream_entry), GFP_KERNEL);
+	stream_entry = kmemdup(stream, sizeof(*stream_entry), GFP_KERNEL);
 	if (!stream_entry)
 		return -ENOMEM;
 
-	memcpy(stream_entry, stream, sizeof(*stream_entry));
-
 	if (!stream->dummy) {
 		ret = vsc9959_mact_stream_set(ocelot, stream_entry, extack);
 		if (ret) {
@@ -1624,11 +1622,10 @@  static int vsc9959_psfp_sfi_list_add(struct ocelot *ocelot,
 	struct felix_stream_filter *sfi_entry;
 	int ret;
 
-	sfi_entry = kzalloc(sizeof(*sfi_entry), GFP_KERNEL);
+	sfi_entry = kmemdup(sfi, sizeof(*sfi_entry), GFP_KERNEL);
 	if (!sfi_entry)
 		return -ENOMEM;
 
-	memcpy(sfi_entry, sfi, sizeof(*sfi_entry));
 	refcount_set(&sfi_entry->refcount, 1);
 
 	ret = vsc9959_psfp_sfi_set(ocelot, sfi_entry);