From: Tariq Toukan
> Sent: 27 November 2016 15:51
> From: Eran Ben Elisha <era...@mellanox.com>
> 
> In order to avoid temporary large structs on the stack,
> allocate them dynamically.
> 
> Signed-off-by: Eran Ben Elisha <era...@mellanox.com>
> Signed-off-by: Tal Alon <ta...@mellanox.com>
> Signed-off-by: Tariq Toukan <tar...@mellanox.com>
> ---
>  drivers/net/ethernet/mellanox/mlx4/main.c | 244 
> +++++++++++++++++-------------
>  1 file changed, 142 insertions(+), 102 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c 
> b/drivers/net/ethernet/mellanox/mlx4/main.c
> index 4a9497e9778d..65502df9fd96 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/main.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
> @@ -799,40 +799,117 @@ static void slave_adjust_steering_mode(struct mlx4_dev 
> *dev,
...
> +static int mlx4_slave_special_qp_cap(struct mlx4_dev *dev)
> +{
> +     struct mlx4_func_cap *func_cap = NULL;
> +     int i, err = 0;
> +
> +     func_cap = kzalloc(sizeof(*func_cap), GFP_KERNEL);
> +     dev->caps.qp0_qkey = kcalloc(dev->caps.num_ports,
> +                                  sizeof(u32), GFP_KERNEL);
> +     dev->caps.qp0_tunnel = kcalloc(dev->caps.num_ports,
> +                                    sizeof(u32), GFP_KERNEL);
> +     dev->caps.qp0_proxy = kcalloc(dev->caps.num_ports,
> +                                   sizeof(u32), GFP_KERNEL);
> +     dev->caps.qp1_tunnel = kcalloc(dev->caps.num_ports,
> +                                    sizeof(u32), GFP_KERNEL);
> +     dev->caps.qp1_proxy = kcalloc(dev->caps.num_ports,
> +                                   sizeof(u32), GFP_KERNEL);
...
It has to be better to allocate a single piece of memory.
Potentially using a structure something like:

struct fubar {
        struct mlx4_func_cap func_cap;
        struct {
                u32     qp0_qkey;
                u32     qp0_tunnel;
                u32     qp0_proxy;
                u32     qp1_tunnel;
                u32     qp1_proxy;
        } port_info[];
};

        David

Reply via email to