linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen: use struct_size() helper in kzalloc()
@ 2019-04-03  5:26 Andrea Righi
  2019-04-03  6:00 ` Juergen Gross
  2019-04-05  6:48 ` Juergen Gross
  0 siblings, 2 replies; 3+ messages in thread
From: Andrea Righi @ 2019-04-03  5:26 UTC (permalink / raw)
  To: Boris Ostrovsky, Juergen Gross
  Cc: Stefano Stabellini, xen-devel, linux-kernel

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>
---
 drivers/xen/privcmd-buf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/xen/privcmd-buf.c b/drivers/xen/privcmd-buf.c
index de01a6d0059d..a1c61e351d3f 100644
--- a/drivers/xen/privcmd-buf.c
+++ b/drivers/xen/privcmd-buf.c
@@ -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;
 
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] xen: use struct_size() helper in kzalloc()
  2019-04-03  5:26 [PATCH] xen: use struct_size() helper in kzalloc() Andrea Righi
@ 2019-04-03  6:00 ` Juergen Gross
  2019-04-05  6:48 ` Juergen Gross
  1 sibling, 0 replies; 3+ messages in thread
From: Juergen Gross @ 2019-04-03  6:00 UTC (permalink / raw)
  To: Andrea Righi, Boris Ostrovsky; +Cc: Stefano Stabellini, xen-devel, linux-kernel

On 03/04/2019 07:26, Andrea Righi wrote:
> 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>


Juergen

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xen: use struct_size() helper in kzalloc()
  2019-04-03  5:26 [PATCH] xen: use struct_size() helper in kzalloc() Andrea Righi
  2019-04-03  6:00 ` Juergen Gross
@ 2019-04-05  6:48 ` Juergen Gross
  1 sibling, 0 replies; 3+ messages in thread
From: Juergen Gross @ 2019-04-05  6:48 UTC (permalink / raw)
  To: Andrea Righi, Boris Ostrovsky; +Cc: Stefano Stabellini, xen-devel, linux-kernel

On 03/04/2019 07:26, Andrea Righi wrote:
> 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>

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


Juergen


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-05  6:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-03  5:26 [PATCH] xen: use struct_size() helper in kzalloc() Andrea Righi
2019-04-03  6:00 ` Juergen Gross
2019-04-05  6:48 ` Juergen Gross

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).