Skip to content

Commit

Permalink
xen: use struct_size() helper in kzalloc()
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
  • Loading branch information
Andrea Righi authored and Juergen Gross committed Apr 5, 2019
1 parent 0266def commit ad94dc3
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/xen/privcmd-buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ad94dc3

Please sign in to comment.