# Re: \[PATCH rdma-next v1 04/11\] RDMA/counter: Add an is\_disabled field in struct rdma\_hw\_stats

- From: Jason Gunthorpe \<jgg@nvidia.com\>
- Date: 2021-09-27 16:53:58 
- List: netdev
- Page: https://ratatoskr.run/netdev/2021/09/1522937
- Thread: https://ratatoskr.run/linux-rdma/2021/09/11211205/t.md

```text
On Wed, Sep 15, 2021 at 02:07:23AM +0300, Leon Romanovsky wrote:

> diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
> index 3f6b98a87566..67519730b1ac 100644
> +++ b/drivers/infiniband/core/nldev.c
> @@ -968,15 +968,21 @@ static int fill_stat_counter_hwcounters(struct sk_buff *msg,
>  	if (!table_attr)
>  		return -EMSGSIZE;
> @@ -601,11 +604,20 @@ static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
>  	if (!stats)
>  		return NULL;
>  
> +	stats->is_disabled = kcalloc(BITS_TO_LONGS(num_counters),
> +				      sizeof(long), GFP_KERNEL);
> +	if (!stats->is_disabled)
> +		goto err;
> +

Please de-inline this function and make a rdma_free_hw_stats_struct()
call to pair with it. The hw_stats_data kfree should be in there. If
you do this as a precursor patch this patch will be much smaller.

Also, the 

        stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64),
                        GFP_KERNEL);

Should be using array_size

Jason
```
