Skip to contentSkip to conversation

xen: use struct_size() helper in kzalloc()

PATCH Applied Andrea Righi 2 participants 5 messages Apr 3, 2019 – Apr 5, 2019 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: use struct_size() helper in kzalloc()

struct privcmd_buf_vma_private has a zero-sized array at the end (pages), use the new struct_size() helper to determine the proper allocation size and avoid potential type mistakes.

---
 drivers/xen/privcmd-buf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/xen/privcmd-buf.c +1 -2
index de01a6d0059d..a1c61e351d3f 100644
@@ -140,8 +140,7 @@ static int privcmd_buf_mmap(struct file *file, struct vm_area_struct *vma)
 	if (!(vma->vm_flags & VM_SHARED))
 		return -EINVAL;
 
-	vma_priv = kzalloc(sizeof(*vma_priv) + count * sizeof(void *),
-			   GFP_KERNEL);
+	vma_priv = kzalloc(struct_size(vma_priv, pages, count), GFP_KERNEL);
 	if (!vma_priv)
 		return -ENOMEM;
 
Signature · 1 line
2.19.1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Andrea Righi
Quoted 5 lines · Andrea Righi

struct privcmd_buf_vma_private has a zero-sized array at the end (pages), use the new struct_size() helper to determine the proper allocation size and avoid potential type mistakes.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

maintainer Applied
#3 lore raw
In reply to Andrea Righi
Quoted 5 lines · Andrea Righi

struct privcmd_buf_vma_private has a zero-sized array at the end (pages), use the new struct_size() helper to determine the proper allocation size and avoid potential type mistakes.

Pushed to xen/tip.git for-linus-5.1b

Juergen

maintainer Applied
#4 lore raw
In reply to Andrea Righi
Quoted 5 lines · Andrea Righi

struct privcmd_buf_vma_private has a zero-sized array at the end (pages), use the new struct_size() helper to determine the proper allocation size and avoid potential type mistakes.

Pushed to xen/tip.git for-linus-5.1b

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel