Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Yihao Han <hanyihao@vivo.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20211207064419.38632-1-hanyihao@vivo.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Yihao Han and committed by
Jakub Kicinski
e44aecc7 d418f67e

+2 -5
+2 -5
drivers/net/dsa/ocelot/felix_vsc9959.c
··· 1505 1505 struct felix_stream *stream_entry; 1506 1506 int ret; 1507 1507 1508 - stream_entry = kzalloc(sizeof(*stream_entry), GFP_KERNEL); 1508 + stream_entry = kmemdup(stream, sizeof(*stream_entry), GFP_KERNEL); 1509 1509 if (!stream_entry) 1510 1510 return -ENOMEM; 1511 - 1512 - memcpy(stream_entry, stream, sizeof(*stream_entry)); 1513 1511 1514 1512 if (!stream->dummy) { 1515 1513 ret = vsc9959_mact_stream_set(ocelot, stream_entry, extack); ··· 1624 1626 struct felix_stream_filter *sfi_entry; 1625 1627 int ret; 1626 1628 1627 - sfi_entry = kzalloc(sizeof(*sfi_entry), GFP_KERNEL); 1629 + sfi_entry = kmemdup(sfi, sizeof(*sfi_entry), GFP_KERNEL); 1628 1630 if (!sfi_entry) 1629 1631 return -ENOMEM; 1630 1632 1631 - memcpy(sfi_entry, sfi, sizeof(*sfi_entry)); 1632 1633 refcount_set(&sfi_entry->refcount, 1); 1633 1634 1634 1635 ret = vsc9959_psfp_sfi_set(ocelot, sfi_entry);