Skip to contentSkip to conversation

ksmbd: Use struct_size() to improve smb_direct_rdma_xmit()

PATCH Applied Thorsten Blum 2 participants 2 messages Sep 28, 2024 – Oct 1, 2024

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

PATCH 1/1 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.

---
 fs/smb/server/transport_rdma.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/server/transport_rdma.c +2 -2
index 44c87e300c16..17c76713c6d0 100644
@@ -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;
Signature · 1 line
2.46.1
maintainer Applied
#1 lore raw
Quoted 5 lines · Thorsten Blum

Use struct_size() to calculate the number of bytes to allocate for a new message.

Applied it to #ksmbd-for-next-next.
Thanks!