From: Junichi Nomura <j-nomura@ce.jp.nec.com>
To: Borislav Petkov <bp@alien8.de>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>,
"x86@kernel.org" <x86@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"mingo@redhat.com" <mingo@redhat.com>,
"hpa@zytor.com" <hpa@zytor.com>
Subject: Re: [PATCH] x86/microcode/intel: Fix allocation size of struct ucode_patch
Date: Fri, 6 Jan 2017 00:14:13 +0000 [thread overview]
Message-ID: <8d24ed6b-9c81-74e3-848d-47ff72b752b4@ce.jp.nec.com> (raw)
In-Reply-To: <20170106000237.5dybkvr35sbba2yx@pd.tnic>
On 01/06/17 09:02, Borislav Petkov wrote:
> On Thu, Jan 05, 2017 at 11:52:07PM +0000, Junichi Nomura wrote:
>>>> + p = kzalloc(sizeof(struct ucode_patch), GFP_KERNEL);
>>>
>>> Perhaps sizeof(*p) ?
>>
>> Yeah, that might be preferred.
>
> No, those things are never preferred because
>
> sizeof(struct <type>)
>
> tells you exactly the size of what kind of object you're getting vs
>
> sizeof(*p)
>
> which tells you you're getting the size of what p points to.
>
> Now you have to go look at p and what type it is. In the current case, p
> is defined not far away from the use site but in a larger function, you
> most likely need to eyeball up to its type when reading the code. Which
> makes the whole thing less readable.
Personally I have same opinion as yours. :)
But according to Documentation/process/coding-style.rst, it seems
"sizeof(*p)" is preferred style and the reason there makes some
sense.
Quote from coding-style.rst:
> The preferred form for passing a size of a struct is the following:
>
> p = kmalloc(sizeof(*p), ...);
>
> The alternative form where struct name is spelled out hurts readability and
> introduces an opportunity for a bug when the pointer variable type is changed
> but the corresponding sizeof that is passed to a memory allocator is not.
I'm fine with either way.
--
Jun'ichi Nomura, NEC Corporation / NEC Solution Innovators, Ltd.
next prev parent reply other threads:[~2017-01-06 0:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-05 1:03 Junichi Nomura
2017-01-05 10:23 ` Borislav Petkov
2017-01-05 17:44 ` Andy Shevchenko
2017-01-05 23:52 ` Junichi Nomura
2017-01-06 0:02 ` Borislav Petkov
2017-01-06 0:14 ` Junichi Nomura [this message]
2017-01-06 10:56 ` Borislav Petkov
2017-01-09 22:17 ` [tip:x86/urgent] " tip-bot for Junichi Nomura
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=8d24ed6b-9c81-74e3-848d-47ff72b752b4@ce.jp.nec.com \
--to=j-nomura@ce.jp.nec.com \
--cc=andy.shevchenko@gmail.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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®