Commit e44aecc7 authored by Yihao Han's avatar Yihao Han Committed by Jakub Kicinski

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

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: default avatarYihao Han <hanyihao@vivo.com>
Reviewed-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20211207064419.38632-1-hanyihao@vivo.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d418f67e
...@@ -1505,12 +1505,10 @@ static int vsc9959_stream_table_add(struct ocelot *ocelot, ...@@ -1505,12 +1505,10 @@ static int vsc9959_stream_table_add(struct ocelot *ocelot,
struct felix_stream *stream_entry; struct felix_stream *stream_entry;
int ret; int ret;
stream_entry = kzalloc(sizeof(*stream_entry), GFP_KERNEL); stream_entry = kmemdup(stream, sizeof(*stream_entry), GFP_KERNEL);
if (!stream_entry) if (!stream_entry)
return -ENOMEM; return -ENOMEM;
memcpy(stream_entry, stream, sizeof(*stream_entry));
if (!stream->dummy) { if (!stream->dummy) {
ret = vsc9959_mact_stream_set(ocelot, stream_entry, extack); ret = vsc9959_mact_stream_set(ocelot, stream_entry, extack);
if (ret) { if (ret) {
...@@ -1626,11 +1624,10 @@ static int vsc9959_psfp_sfi_list_add(struct ocelot *ocelot, ...@@ -1626,11 +1624,10 @@ static int vsc9959_psfp_sfi_list_add(struct ocelot *ocelot,
struct felix_stream_filter *sfi_entry; struct felix_stream_filter *sfi_entry;
int ret; int ret;
sfi_entry = kzalloc(sizeof(*sfi_entry), GFP_KERNEL); sfi_entry = kmemdup(sfi, sizeof(*sfi_entry), GFP_KERNEL);
if (!sfi_entry) if (!sfi_entry)
return -ENOMEM; return -ENOMEM;
memcpy(sfi_entry, sfi, sizeof(*sfi_entry));
refcount_set(&sfi_entry->refcount, 1); refcount_set(&sfi_entry->refcount, 1);
ret = vsc9959_psfp_sfi_set(ocelot, sfi_entry); ret = vsc9959_psfp_sfi_set(ocelot, sfi_entry);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment