On 1/5/24 10:39, Harshit Mogalapalli wrote:
Use struct_size() instead of open coding.

Suggested-by: Gustavo A. R. Silva <[email protected]>
Signed-off-by: Harshit Mogalapalli <[email protected]>

Reviewed-by: Gustavo A. R. Silva <[email protected]>

Thanks!
--
Gustavo

---
  drivers/misc/vmw_vmci/vmci_datagram.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/vmw_vmci/vmci_datagram.c 
b/drivers/misc/vmw_vmci/vmci_datagram.c
index f50d22882476..ac6cb0c8d99b 100644
--- a/drivers/misc/vmw_vmci/vmci_datagram.c
+++ b/drivers/misc/vmw_vmci/vmci_datagram.c
@@ -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);

Reply via email to