From: "linyujun (C)" <linyujun809@huawei.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: <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>, <linux-perf-users@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <johnny.chenyi@huawei.com>,
<chenjiahao16@huawei.com>, <chenlifu@huawei.com>,
<lizhengyu3@huawei.com>, <liaochang1@huawei.com>,
<wangzhu9@huawei.com>, <xuyihang@huawei.com>,
<chris.zjh@huawei.com>, <zouyipeng@huawei.com>
Subject: Re: [PATCH -next] x86/events:Use struct_size() helper in kzalloc()
Date: Thu, 19 May 2022 10:30:40 +0800 [thread overview]
Message-ID: <6eb03912-4292-8a5f-2103-eea401eccf08@huawei.com> (raw)
In-Reply-To: <20220518134920.GA8361@embeddedor>
Thank you for your suggestion. I will modify the patch according
to your suggestion and make the v2 version.
Thanks
--
LinYujun
在 2022/5/18 21:49, Gustavo A. R. Silva 写道:
> On Wed, May 18, 2022 at 09:16:26PM +0800, Lin Yujun wrote:
>> Replace sizeof() with struct_size() to avoid potential integer
>> or heap overflow.
> This is not exactly what the patch does.
>
> Your patch is replacing the open-coded calculation of the total amount
> of memory to be allocated for rapl_pmus with struct_size().
>
>> Also, address the following sparse warnings:
>> arch/x86/events/rapl.c:685:16: warning: using sizeof on a
>> flexible structure
> This does not address this warning because struct_size()
> still make use of sizeof on the struct-with-flex-array,
> internally.
>
> So, the mention to the sparse warning should be removed from
> this changelog text.
>
>> Signed-off-by: Lin Yujun <linyujun809@huawei.com>
>> ---
>> arch/x86/events/rapl.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
>> index 77e3a47af5ad..c7e79f0ac04f 100644
>> --- a/arch/x86/events/rapl.c
>> +++ b/arch/x86/events/rapl.c
>> @@ -685,7 +685,7 @@ 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 *);
>> + size = struct_size(rapl_pmus, pmus, maxdie);
>> rapl_pmus = kzalloc(size, GFP_KERNEL);
> It seems that in this case, size could be entirely replaced by
> struct_size().
>
> Thanks
> --
> Gustavo
> .
prev parent reply other threads:[~2022-05-19 2:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-18 13:16 [PATCH -next] x86/events:Use struct_size() helper in kzalloc() Lin Yujun
2022-05-18 13:49 ` Gustavo A. R. Silva
2022-05-18 13:55 ` Peter Zijlstra
2022-05-18 16:03 ` Gustavo A. R. Silva
2022-05-18 16:54 ` Borislav Petkov
2022-05-19 2:30 ` linyujun (C) [this message]
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=6eb03912-4292-8a5f-2103-eea401eccf08@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;
as well as URLs for NNTP newsgroup(s).