public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/mlx5e: use flex array for rqns
@ 2026-03-04  4:20 Rosen Penev
  2026-03-04  8:29 ` Tariq Toukan
  0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-04  4:20 UTC (permalink / raw)
  To: netdev
  Cc: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch,
	Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, open list:MELLANOX MLX5 core VPI driver, open list

Simplifies allocation. Separate kcalloc and kfree not needed anymore.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c
index 92974b11ec75..fc71dd72938c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c
@@ -16,7 +16,6 @@ struct mlx5e_rx_res {
 
 	struct mlx5e_rss *rss[MLX5E_MAX_NUM_RSS];
 	bool rss_active;
-	u32 *rss_rqns;
 	u32 *rss_vhca_ids;
 	unsigned int rss_nch;
 
@@ -29,6 +28,8 @@ struct mlx5e_rx_res {
 		struct mlx5e_rqt rqt;
 		struct mlx5e_tir tir;
 	} ptp;
+
+	u32 rss_rqns[];
 };
 
 /* API for rx_res_rss_* */
@@ -316,7 +317,6 @@ struct mlx5e_rss *mlx5e_rx_res_rss_get(struct mlx5e_rx_res *res, u32 rss_idx)
 static void mlx5e_rx_res_free(struct mlx5e_rx_res *res)
 {
 	kvfree(res->rss_vhca_ids);
-	kvfree(res->rss_rqns);
 	kvfree(res);
 }
 
@@ -325,20 +325,13 @@ static struct mlx5e_rx_res *mlx5e_rx_res_alloc(struct mlx5_core_dev *mdev, unsig
 {
 	struct mlx5e_rx_res *rx_res;
 
-	rx_res = kvzalloc_obj(*rx_res);
+	rx_res = kvzalloc_flex(*rx_res, rss_rqns, max_nch, GFP_KERNEL);
 	if (!rx_res)
 		return NULL;
 
-	rx_res->rss_rqns = kvcalloc(max_nch, sizeof(*rx_res->rss_rqns), GFP_KERNEL);
-	if (!rx_res->rss_rqns) {
-		kvfree(rx_res);
-		return NULL;
-	}
-
 	if (multi_vhca) {
 		rx_res->rss_vhca_ids = kvcalloc(max_nch, sizeof(*rx_res->rss_vhca_ids), GFP_KERNEL);
 		if (!rx_res->rss_vhca_ids) {
-			kvfree(rx_res->rss_rqns);
 			kvfree(rx_res);
 			return NULL;
 		}
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net/mlx5e: use flex array for rqns
  2026-03-04  4:20 [PATCH] net/mlx5e: use flex array for rqns Rosen Penev
@ 2026-03-04  8:29 ` Tariq Toukan
  0 siblings, 0 replies; 2+ messages in thread
From: Tariq Toukan @ 2026-03-04  8:29 UTC (permalink / raw)
  To: Rosen Penev, netdev
  Cc: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch,
	Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, open list:MELLANOX MLX5 core VPI driver, open list



On 04/03/2026 6:20, Rosen Penev wrote:
> Simplifies allocation. Separate kcalloc and kfree not needed anymore.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>   drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c | 13 +++----------
>   1 file changed, 3 insertions(+), 10 deletions(-)
> 

This is not the typical structure that matches the usage of kvzalloc_flex().

I prefer keeping current code, being consistent with other dynamically 
allocated members like rss_vhca_ids.


> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c
> index 92974b11ec75..fc71dd72938c 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c
> @@ -16,7 +16,6 @@ struct mlx5e_rx_res {
>   
>   	struct mlx5e_rss *rss[MLX5E_MAX_NUM_RSS];
>   	bool rss_active;
> -	u32 *rss_rqns;
>   	u32 *rss_vhca_ids;
>   	unsigned int rss_nch;
>   
> @@ -29,6 +28,8 @@ struct mlx5e_rx_res {
>   		struct mlx5e_rqt rqt;
>   		struct mlx5e_tir tir;
>   	} ptp;
> +
> +	u32 rss_rqns[];
>   };
>   
>   /* API for rx_res_rss_* */
> @@ -316,7 +317,6 @@ struct mlx5e_rss *mlx5e_rx_res_rss_get(struct mlx5e_rx_res *res, u32 rss_idx)
>   static void mlx5e_rx_res_free(struct mlx5e_rx_res *res)
>   {
>   	kvfree(res->rss_vhca_ids);
> -	kvfree(res->rss_rqns);
>   	kvfree(res);
>   }
>   
> @@ -325,20 +325,13 @@ static struct mlx5e_rx_res *mlx5e_rx_res_alloc(struct mlx5_core_dev *mdev, unsig
>   {
>   	struct mlx5e_rx_res *rx_res;
>   
> -	rx_res = kvzalloc_obj(*rx_res);
> +	rx_res = kvzalloc_flex(*rx_res, rss_rqns, max_nch, GFP_KERNEL);
>   	if (!rx_res)
>   		return NULL;
>   
> -	rx_res->rss_rqns = kvcalloc(max_nch, sizeof(*rx_res->rss_rqns), GFP_KERNEL);
> -	if (!rx_res->rss_rqns) {
> -		kvfree(rx_res);
> -		return NULL;
> -	}
> -
>   	if (multi_vhca) {
>   		rx_res->rss_vhca_ids = kvcalloc(max_nch, sizeof(*rx_res->rss_vhca_ids), GFP_KERNEL);
>   		if (!rx_res->rss_vhca_ids) {
> -			kvfree(rx_res->rss_rqns);
>   			kvfree(rx_res);
>   			return NULL;
>   		}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-04  8:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04  4:20 [PATCH] net/mlx5e: use flex array for rqns Rosen Penev
2026-03-04  8:29 ` Tariq Toukan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox