From a68cd7230b94e302c3f5ce30c5b91b6caa6f8031 Mon Sep 17 00:00:00 2001 From: Thorsten Blum Date: Sun, 13 Oct 2024 22:01:18 +0900 Subject: [PATCH] ksmbd: Use struct_size() to improve smb_direct_rdma_xmit() Use struct_size() to calculate the number of bytes to allocate for a new message. Signed-off-by: Thorsten Blum Signed-off-by: Namjae Jeon --- transport_rdma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transport_rdma.c b/transport_rdma.c index bd3be2b85..d37e961ed 100644 --- a/transport_rdma.c +++ b/transport_rdma.c @@ -1405,8 +1405,8 @@ static int smb_direct_rdma_xmit(struct smb_direct_transport *t, /* build rdma_rw_ctx for each descriptor */ desc_buf = buf; for (i = 0; i < desc_num; i++) { - msg = kzalloc(offsetof(struct smb_direct_rdma_rw_msg, sg_list) + - sizeof(struct scatterlist) * SG_CHUNK_SIZE, GFP_KERNEL); + msg = kzalloc(struct_size(msg, sg_list, SG_CHUNK_SIZE), + GFP_KERNEL); if (!msg) { ret = -ENOMEM; goto out;