diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c index e9b8d79d2d21..44296789d656 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c @@ -101,14 +101,18 @@ unlock: static int mapping_show(struct seq_file *file, void *priv) { struct mlx5_core_dev *dev = file->private; - u8 ports[MLX5_MAX_PORTS] = {}; struct mlx5_lag *ldev; bool hash = false; bool lag_active; int i, idx = 0; int num_ports; + u8 *ports; ldev = mlx5_lag_dev(dev); + ports = kcalloc(ldev->ports, sizeof(*ports), GFP_KERNEL); + if (!ports) + return -ENOMEM; + mutex_lock(&ldev->lock); lag_active = __mlx5_lag_is_active(ldev); if (lag_active) { @@ -123,8 +127,10 @@ static int mapping_show(struct seq_file *file, void *priv) } } mutex_unlock(&ldev->lock); - if (!lag_active) + if (!lag_active) { + kfree(ports); return -EINVAL; + } for (i = 0; i < num_ports; i++) { if (hash) @@ -133,6 +139,7 @@ static int mapping_show(struct seq_file *file, void *priv) seq_printf(file, "%d:%d\n", i + 1, ports[i]); } + kfree(ports); return 0; }