Message ID | 20230630014903.1082615-3-shaozhengchao@huawei.com (mailing list archive) |
---|---|
State | Handled Elsewhere |
Headers | show |
Series | fix two memory leak issues for mlx5en driver | expand |
On Fri, Jun 30, 2023 at 09:49:03AM +0800, Zhengchao Shao wrote: > When kvzalloc_node or kvzalloc failed in mlx5e_ptp_open, the memory > pointed by "c" or "cparams" is not freed, which can lead to a memory > leak. Fix by freeing the array in the error path. > > Fixes: 145e5637d941 ("net/mlx5e: Add TX PTP port object support") > Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com> > Reviewed-by: Rahul Rameshbabu <rrameshbabu@nvidia.com> > Reviewed-by: Gal Pressman <gal@nvidia.com> Reviewed-by: Simon Horman <simon.horman@corigine.com>
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c b/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c index 3cbebfba582b..b0b429a0321e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c @@ -729,8 +729,10 @@ int mlx5e_ptp_open(struct mlx5e_priv *priv, struct mlx5e_params *params, c = kvzalloc_node(sizeof(*c), GFP_KERNEL, dev_to_node(mlx5_core_dma_dev(mdev))); cparams = kvzalloc(sizeof(*cparams), GFP_KERNEL); - if (!c || !cparams) - return -ENOMEM; + if (!c || !cparams) { + err = -ENOMEM; + goto err_free; + } c->priv = priv; c->mdev = priv->mdev;