VMCI: Use struct_size() in kmalloc()
authorHarshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Fri, 5 Jan 2024 16:39:59 +0000 (08:39 -0800)
committerKees Cook <keescook@chromium.org>
Thu, 1 Feb 2024 18:06:42 +0000 (10:06 -0800)
Use struct_size() instead of open coding.

Suggested-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20240105164001.2129796-1-harshit.m.mogalapalli@oracle.com
Signed-off-by: Kees Cook <keescook@chromium.org>
drivers/misc/vmw_vmci/vmci_datagram.c

index f50d22882476f943fbf7ac2c7d15c82379dd126e..ac6cb0c8d99b81038125ff8b7e230071e3155cf3 100644 (file)
@@ -224,8 +224,8 @@ static int dg_dispatch_as_host(u32 context_id, struct vmci_datagram *dg)
                                return VMCI_ERROR_NO_MEM;
                        }
 
-                       dg_info = kmalloc(sizeof(*dg_info) +
-                                   (size_t) dg->payload_size, GFP_ATOMIC);
+                       dg_info = kmalloc(struct_size(dg_info, msg_payload, dg->payload_size),
+                                         GFP_ATOMIC);
                        if (!dg_info) {
                                atomic_dec(&delayed_dg_host_queue_size);
                                vmci_resource_put(resource);