Subject: Re: [PATCH rdma-next v2 04/13] RDMA/core: Add a helper API rdma_free_hw_stats_struct

From: Jason Gunthorpe <[email-masked]>
Date: Mon, 4 Oct 2021 14:59:06 -0300

On Thu, Sep 30, 2021 at 11:02:20AM +0300, Leon Romanovsky wrote:

> +
> +struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
> +	const struct rdma_stat_desc *descs, int num_counters,
> +	unsigned long lifespan)
> +{

The kdoc should be moved here too from the header

> +	struct rdma_hw_stats *stats;
> +
> +	stats = kzalloc(struct_size(stats, value, num_counters), GFP_KERNEL);
> +	if (!stats)
> +		return NULL;
> +
> +	stats->descs = descs;
> +	stats->num_counters = num_counters;
> +	stats->lifespan = msecs_to_jiffies(lifespan);
> +
> +	return stats;
> +}
> +EXPORT_SYMBOL(rdma_alloc_hw_stats_struct);
> +
> +void rdma_free_hw_stats_struct(struct rdma_hw_stats *stats)
> +{
> +	kfree(stats);
> +}
> +EXPORT_SYMBOL(rdma_free_hw_stats_struct);
> diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
> index aa1e1029b736..5e8a5ed47e9a 100644
> +++ b/include/rdma/ib_verbs.h
> @@ -589,24 +589,14 @@ struct rdma_hw_stats {
>   * @num_counters - How many elements in array
>   * @lifespan - How many milliseconds between updates
>   */
> -static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
> -		const struct rdma_stat_desc *descs, int num_counters,
> -		unsigned long lifespan)
> -{
> -	struct rdma_hw_stats *stats;
> -
> -	stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64),
> -			GFP_KERNEL);
> -	if (!stats)
> -		return NULL;
> -
> -	stats->descs = descs;
> -	stats->num_counters = num_counters;
> -	stats->lifespan = msecs_to_jiffies(lifespan);
> -
> -	return stats;
> -}
> +struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
> +	const struct rdma_stat_desc *descs, int num_counters,
> +	unsigned long lifespan);
>  
> +/**
> + * rdma_free_hw_stats_struct - Helper function to release rdma_hw_stats
> + */
> +void rdma_free_hw_stats_struct(struct rdma_hw_stats *stats);

Ditto

Jason