Subject: Re: [net-next V3 11/15] net/mlx5: HWS, added memory management handling

From: Simon Horman <[email-masked]>
Date: Sat, 7 Sep 2024 15:28:06 +0100

On Fri, Sep 06, 2024 at 02:54:06PM -0700, Saeed Mahameed wrote:
> From: Yevgeny Kliteynik <[email-masked]>
> 
> Added object pools and buddy allocator functionality.
> 
> Reviewed-by: Itamar Gozlan <[email-masked]>
> Signed-off-by: Yevgeny Kliteynik <[email-masked]>
> Signed-off-by: Saeed Mahameed <[email-masked]>

...

> +static struct mlx5hws_pool_resource *
> +hws_pool_create_one_resource(struct mlx5hws_pool *pool, u32 log_range,
> +			     u32 fw_ft_type)
> +{
> +	struct mlx5hws_cmd_ste_create_attr ste_attr;
> +	struct mlx5hws_cmd_stc_create_attr stc_attr;
> +	struct mlx5hws_pool_resource *resource;
> +	u32 obj_id;
> +	int ret;
> +
> +	resource = kzalloc(sizeof(*resource), GFP_KERNEL);
> +	if (!resource)
> +		return NULL;
> +
> +	switch (pool->type) {
> +	case MLX5HWS_POOL_TYPE_STE:
> +		ste_attr.log_obj_range = log_range;
> +		ste_attr.table_type = fw_ft_type;
> +		ret = mlx5hws_cmd_ste_create(pool->ctx->mdev, &ste_attr, &obj_id);
> +		break;
> +	case MLX5HWS_POOL_TYPE_STC:
> +		stc_attr.log_obj_range = log_range;
> +		stc_attr.table_type = fw_ft_type;
> +		ret = mlx5hws_cmd_stc_create(pool->ctx->mdev, &stc_attr, &obj_id);
> +		break;
> +	default:
> +		return NULL;

Sorry, but this now appears to leak resource. Maybe:

		goto free_resource;

Or:

		ret = -EINVAL;

> +	}
> +
> +	if (ret) {
> +		mlx5hws_err(pool->ctx, "Failed to allocate resource objects\n");
> +		goto free_resource;
> +	}
> +
> +	resource->pool = pool;
> +	resource->range = 1 << log_range;
> +	resource->base_id = obj_id;
> +
> +	return resource;
> +
> +free_resource:
> +	kfree(resource);
> +	return NULL;
> +}

...

-- 
pw-bot: cr