vdpa/mlx5: Use kvzalloc_flex() for MTT command memory
Subsystems (2)
PATCH 1/1 vdpa/mlx5: Use kvzalloc_flex() for MTT command memory
The create mkey command memory embeds the MTT array as a flexible array member. Use kvzalloc_flex() to allocate it directly instead of open-coding the struct_size() calculation with kvcalloc().
The MTT allocation still needs to be aligned to MLX5_VDPA_MTT_ALIGN bytes. Since each MTT entry is __be64, align the entry count directly and avoid carrying a separate byte length variable.
--- drivers/vdpa/mlx5/core/mr.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/vdpa/mlx5/core/mr.c +3 -4
@@ -221,11 +221,10 @@ static int create_direct_keys(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *list_for_each_entry (dmr, &mr->head, list) {struct mlx5_create_mkey_mem *cmd_mem; -int mttlen, mttcount; +int mttcount; - mttlen =roundup (MLX5_ST_SZ_BYTES (mtt) * dmr->nsg,MLX5_VDPA_MTT_ALIGN ); - mttcount = mttlen /sizeof (cmd_mem->mtt[0 ]); - cmd_mem =kvcalloc (1 ,struct_size (cmd_mem, mtt, mttcount),GFP_KERNEL ); + mttcount =ALIGN (dmr->nsg,MLX5_VDPA_MTT_ALIGN /sizeof (cmd_mem->mtt[0 ])); + cmd_mem =kvzalloc_flex (*cmd_mem, mtt, mttcount);if (!cmd_mem) { err = -ENOMEM ; goto done;
Signature · 1 line
2.54.0
Quoted 36 lines · Rosen Penev
The create mkey command memory embeds the MTT array as a flexible array member. Use
kvzalloc_flex()to allocate it directly instead of open-coding thestruct_size()calculation withkvcalloc().The MTT allocation still needs to be aligned to
MLX5_VDPA_MTT_ALIGNbytes. Since each MTT entry is__be64, align the entry count directly and avoid carrying a separate byte length variable.Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- drivers/vdpa/mlx5/core/mr.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/vdpa/mlx5/core/mr.c +3
-4@@ -221,11 +221,10 @@ static int create_direct_keys(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *list_for_each_entry (dmr, &mr->head, list) {struct mlx5_create_mkey_mem *cmd_mem; -int mttlen, mttcount; +int mttcount; - mttlen =roundup (MLX5_ST_SZ_BYTES (mtt) * dmr->nsg,MLX5_VDPA_MTT_ALIGN ); - mttcount = mttlen /sizeof (cmd_mem->mtt[0 ]); - cmd_mem =kvcalloc (1 ,struct_size (cmd_mem, mtt, mttcount),GFP_KERNEL ); + mttcount =ALIGN (dmr->nsg,MLX5_VDPA_MTT_ALIGN /sizeof (cmd_mem->mtt[0 ])); + cmd_mem =kvzalloc_flex (*cmd_mem, mtt, mttcount);if (!cmd_mem) { err = -ENOMEM ; goto done;Signature · 1 line
2.54.0
Thanks for the patch. Code and commit message looks good. Not sure about the Assisted-by tag, but that is not my call.
Thanks,
Dragos