[PATCH] net/mlx5: use kmemdup() to replace kzalloc + memcpy

From: Jiapeng Chong
Date: Fri Sep 09 2022 - 01:43:16 EST


./drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c:932:27-34: WARNING opportunity for kmemdup.

Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=2107
Reported-by: Abaci Robot <abaci@xxxxxxxxxxxxxxxxx>
Signed-off-by: Jiapeng Chong <jiapeng.chong@xxxxxxxxxxxxxxxxx>
---
drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
index d9d18b039d8c..e32892943ee5 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
@@ -929,14 +929,13 @@ static int mlx5e_macsec_add_secy(struct macsec_context *ctx)
goto out;
}

- macsec_device->dev_addr = kzalloc(dev->addr_len, GFP_KERNEL);
+ macsec_device->dev_addr = kmemdup(dev->dev_addr, dev->addr_len, GFP_KERNEL);
if (!macsec_device->dev_addr) {
kfree(macsec_device);
err = -ENOMEM;
goto out;
}

- memcpy(macsec_device->dev_addr, dev->dev_addr, dev->addr_len);
macsec_device->netdev = dev;

INIT_LIST_HEAD_RCU(&macsec_device->macsec_rx_sc_list_head);
--
2.20.1.7.g153144c