Skip to contentSkip to conversation

net/mlx5: convert miss_list allocation to kvmalloc_array()

PATCH Applied William Theesfeld 4 participants 4 messages Jun 1 – Jun 4

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5: convert miss_list allocation to kvmalloc_array()

dr_icm_buddy_init_ste_cache() allocates the per-buddy miss_list using the open-coded kvmalloc(n * sizeof(*p), ...) form. The neighbouring allocations in the same function already use the kvcalloc()/ kvzalloc_objs() forms; switch this last one to kvmalloc_array() for consistency and for the size_mul overflow check that kvmalloc_array() performs.

The semantics are unchanged: kvmalloc_array() returns a non-zeroed buffer, just like the previous kvmalloc() call. Existing callers of buddy->miss_list initialise each list_head before use.

---
 .../net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c +1 -1
index 7a0a15822..fa4d24b3d 100644
@@ -239,7 +239,7 @@ static int dr_icm_buddy_init_ste_cache(struct mlx5dr_icm_buddy_mem *buddy)
 	if (!buddy->hw_ste_arr)
 		goto free_ste_arr;
 
-	buddy->miss_list = kvmalloc(num_of_entries * sizeof(struct list_head), GFP_KERNEL);
+	buddy->miss_list = kvmalloc_array(num_of_entries, sizeof(struct list_head), GFP_KERNEL);
 	if (!buddy->miss_list)
 		goto free_hw_ste_arr;
 
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 21 lines · William Theesfeld

dr_icm_buddy_init_ste_cache() allocates the per-buddy miss_list using the open-coded kvmalloc(n * sizeof(*p), ...) form. The neighbouring allocations in the same function already use the kvcalloc()/ kvzalloc_objs() forms; switch this last one to kvmalloc_array() for consistency and for the size_mul overflow check that kvmalloc_array() performs.

The semantics are unchanged: kvmalloc_array() returns a non-zeroed buffer, just like the previous kvmalloc() call. Existing callers of buddy->miss_list initialise each list_head before use.

---
 .../net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c +0 -0
index 7a0a15822..fa4d24b3d 100644

drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c static int dr_icm_buddy_init_ste_cache(struct mlx5dr_icm_buddy_mem *buddy) · line 244

Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c +1 -1
@@ -239,7 +239,7 @@ static int dr_icm_buddy_init_ste_cache(struct mlx5dr_icm_buddy_mem *buddy)
 	if (!buddy->hw_ste_arr)
 		goto free_ste_arr;
 
-	buddy->miss_list = kvmalloc(num_of_entries * sizeof(struct list_head), GFP_KERNEL);
+	buddy->miss_list = kvmalloc_array(num_of_entries, sizeof(struct list_head), GFP_KERNEL);
 	if (!buddy->miss_list)
 		goto free_hw_ste_arr;

@Leon, @Tariq: the patch looks obviously correct to me, still an explicit ack would be nice, I think.

Thanks,

Paolo

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to William Theesfeld
Quoted 21 lines · William Theesfeld

dr_icm_buddy_init_ste_cache() allocates the per-buddy miss_list using the open-coded kvmalloc(n * sizeof(*p), ...) form. The neighbouring allocations in the same function already use the kvcalloc()/ kvzalloc_objs() forms; switch this last one to kvmalloc_array() for consistency and for the size_mul overflow check that kvmalloc_array() performs.

The semantics are unchanged: kvmalloc_array() returns a non-zeroed buffer, just like the previous kvmalloc() call. Existing callers of buddy->miss_list initialise each list_head before use.

---
  .../net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c  | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c +0 -0
index 7a0a15822..fa4d24b3d 100644

drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c static int dr_icm_buddy_init_ste_cache(struct mlx5dr_icm_buddy_mem *buddy) · line 245

Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c +1 -1
@@ -239,7 +239,7 @@ static int dr_icm_buddy_init_ste_cache(struct mlx5dr_icm_buddy_mem *buddy)
  	if (!buddy->hw_ste_arr)
  		goto free_ste_arr;
 
-	buddy->miss_list = kvmalloc(num_of_entries * sizeof(struct list_head), GFP_KERNEL);
+	buddy->miss_list = kvmalloc_array(num_of_entries, sizeof(struct list_head), GFP_KERNEL);
  	if (!buddy->miss_list)
  		goto free_hw_ste_arr;
 

Thanks for your patch.

#3 lore raw
In reply to William Theesfeld
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 1 Jun 2026 15:37:58 -0400 you wrote:

dr_icm_buddy_init_ste_cache() allocates the per-buddy miss_list using the open-coded kvmalloc(n * sizeof(*p), ...) form. The neighbouring allocations in the same function already use the kvcalloc()/ kvzalloc_objs() forms; switch this last one to kvmalloc_array() for consistency and for the size_mul overflow check that kvmalloc_array() performs.

[...]

Here is the summary with links:
- net/mlx5: convert miss_list allocation to kvmalloc_array()

    https://git.kernel.org/netdev/net-next/c/93790c374b9d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html