From: "tip-bot for Gustavo A. R. Silva" <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: tglx@linutronix.de, gustavo@embeddedor.com,
linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com
Subject: [tip:x86/cleanups] x86/kexec/crash: Use struct_size() in vzalloc()
Date: Fri, 5 Apr 2019 04:22:05 -0700 [thread overview]
Message-ID: <tip-4df4309587e18a3c91e68138638dcb9d2a968906@git.kernel.org> (raw)
In-Reply-To: <20190403184230.GA5295@embeddedor>
Commit-ID: 4df4309587e18a3c91e68138638dcb9d2a968906
Gitweb: https://git.kernel.org/tip/4df4309587e18a3c91e68138638dcb9d2a968906
Author: Gustavo A. R. Silva <gustavo@embeddedor.com>
AuthorDate: Wed, 3 Apr 2019 13:42:30 -0500
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Fri, 5 Apr 2019 13:18:38 +0200
x86/kexec/crash: Use struct_size() in vzalloc()
One of the more common cases of allocation size calculations is finding the
size of a structure that has a zero-sized array at the end, along with
memory for some number of elements for that array. For example:
struct foo {
int stuff;
struct boo entry[];
};
instance = vzalloc(sizeof(struct foo) + count * sizeof(struct boo));
Instead of leaving these open-coded and prone to type mistakes, use the new
struct_size() helper:
instance = vzalloc(struct_size(instance, entry, count));
This code was detected with the help of Coccinelle.
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lkml.kernel.org/r/20190403184230.GA5295@embeddedor
---
arch/x86/kernel/crash.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 17ffc869cab8..a96ca8584803 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -204,8 +204,7 @@ static struct crash_mem *fill_up_crash_elf_data(void)
* another range split. So add extra two slots here.
*/
nr_ranges += 2;
- cmem = vzalloc(sizeof(struct crash_mem) +
- sizeof(struct crash_mem_range) * nr_ranges);
+ cmem = vzalloc(struct_size(cmem, ranges, nr_ranges));
if (!cmem)
return NULL;
parent reply other threads:[~2019-04-05 11:22 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20190403184230.GA5295@embeddedor>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-4df4309587e18a3c91e68138638dcb9d2a968906@git.kernel.org \
--to=tipbot@zytor.com \
--cc=gustavo@embeddedor.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome