nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] device-dax/kmem: Use struct_size()
@ 2020-10-16 21:10 Dan Williams
  2020-10-17 18:38 ` Linus Torvalds
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Williams @ 2020-10-16 21:10 UTC (permalink / raw)
  To: akpm; +Cc: Linus Torvalds, linux-mm, linux-nvdimm

Linus notes the kernel has had a nice helper for the 'size of struct
with variable array member at the end' operation for a couple years
now, use it.

Link: http://lore.kernel.org/r/CAHk-=wgNTLbvAD8mNTvh+GQyapNWeX20PXhU_+frqEvVq4298w@mail.gmail.com
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 drivers/dax/kmem.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c
index b4368c5b6a0c..403ec42472d1 100644
--- a/drivers/dax/kmem.c
+++ b/drivers/dax/kmem.c
@@ -61,7 +61,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
 		return -EINVAL;
 	}
 
-	data = kzalloc(sizeof(*data) + sizeof(struct resource *) * dev_dax->nr_range, GFP_KERNEL);
+	data = kzalloc(struct_size(data, res, dev_dax->nr_range), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

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

end of thread, other threads:[~2020-10-18  0:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-16 21:10 [PATCH] device-dax/kmem: Use struct_size() Dan Williams
2020-10-17 18:38 ` Linus Torvalds
2020-10-17 20:54   ` Dan Williams
2020-10-17 21:43     ` Andrew Morton
2020-10-18  0:05       ` Linus Torvalds
2020-10-17 21:38   ` Konstantin Ryabitsev

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).