From: Lin Yujun <linyujun809@huawei.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
<jolsa@kernel.org>, <namhyung@kernel.org>, <tglx@linutronix.de>,
<bp@alien8.de>, <dave.hansen@linux.intel.com>, <x86@kernel.org>,
<hpa@zytor.com>
Cc: <linux-perf-users@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <gustavoars@kernel.org>,
<johnny.chenyi@huawei.com>, <chenjiahao16@huawei.com>,
<chenlifu@huawei.com>, <lizhengyu3@huawei.com>,
<liaochang1@huawei.com>, <linyujun809@huawei.com>,
<wangzhu9@huawei.com>, <xuyihang@huawei.com>,
<chris.zjh@huawei.com>, <zouyipeng@huawei.com>
Subject: [PATCH -next v2] x86/events:Use struct_size() helper in kzalloc()
Date: Thu, 19 May 2022 10:36:00 +0800 [thread overview]
Message-ID: <20220519023600.241591-1-linyujun809@huawei.com> (raw)
Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worst scenario, could lead to heap overflows.
Signed-off-by: Lin Yujun <linyujun809@huawei.com>
---
arch/x86/events/rapl.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index 77e3a47af5ad..8da003e02010 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -683,10 +683,8 @@ static const struct attribute_group *rapl_attr_update[] = {
static int __init init_rapl_pmus(void)
{
int maxdie = topology_max_packages() * topology_max_die_per_package();
- size_t size;
- size = sizeof(*rapl_pmus) + maxdie * sizeof(struct rapl_pmu *);
- rapl_pmus = kzalloc(size, GFP_KERNEL);
+ rapl_pmus = kzalloc(struct_size(rapl_pmus, pmus, maxdie), GFP_KERNEL);
if (!rapl_pmus)
return -ENOMEM;
--
2.17.1
next reply other threads:[~2022-05-19 2:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-19 2:36 Lin Yujun [this message]
2022-05-19 7:52 ` Peter Zijlstra
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=20220519023600.241591-1-linyujun809@huawei.com \
--to=linyujun809@huawei.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=bp@alien8.de \
--cc=chenjiahao16@huawei.com \
--cc=chenlifu@huawei.com \
--cc=chris.zjh@huawei.com \
--cc=dave.hansen@linux.intel.com \
--cc=gustavoars@kernel.org \
--cc=hpa@zytor.com \
--cc=johnny.chenyi@huawei.com \
--cc=jolsa@kernel.org \
--cc=liaochang1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=lizhengyu3@huawei.com \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=wangzhu9@huawei.com \
--cc=x86@kernel.org \
--cc=xuyihang@huawei.com \
--cc=zouyipeng@huawei.com \
/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
all inboxes | Powered by JetHome®