Message ID | 20220913143713.1998778-2-yangyingliang@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [-next,1/2] net/mlx5e: add missing error code in error path | expand |
>-----Original Message----- >From: Yang Yingliang <yangyingliang@huawei.com> >Sent: Tuesday, 13 September 2022 17:37 >To: netdev@vger.kernel.org; linux-rdma@vger.kernel.org >Cc: Saeed Mahameed <saeedm@nvidia.com>; Lior Nahmanson ><liorna@nvidia.com>; Raed Salem <raeds@nvidia.com>; >davem@davemloft.net >Subject: [PATCH -next 2/2] net/mlx5e: Switch to kmemdup() when allocate >dev_addr > >External email: Use caution opening links or attachments > > >Use kmemdup() helper instead of open-coding to simplify the code when >allocate dev_addr. > >Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> >--- > drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c | 4 ++-- > 1 file changed, 2 insertions(+), 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 5fa3e22c8918..0f7c5b9a3541 100644 >--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c >+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c >@@ -934,14 +934,14 @@ 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); I think it could fit in one line (the kmemdup function call) > 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.25.1 Thanks, good catch
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 5fa3e22c8918..0f7c5b9a3541 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c @@ -934,14 +934,14 @@ 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);
Use kmemdup() helper instead of open-coding to simplify the code when allocate dev_addr. Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> --- drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)