From: Hagen Paul Pfeifer <hagen@jauu.net>
To: Thiago Farina <tfransosi@gmail.com>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>,
Liam Girdwood <lrg@slimlogic.co.uk>,
linux list <linux-kernel@vger.kernel.org>
Subject: Re: regulators: kzalloc doubt
Date: Tue, 3 May 2011 23:58:29 +0200 [thread overview]
Message-ID: <20110503215828.GJ5352@nuttenaction> (raw)
In-Reply-To: <BANLkTik4bW7nRMFXKW-UpfrSsaimEQ=zWg@mail.gmail.com>
* Thiago Farina | 2011-05-03 18:54:13 [-0300]:
>What is the preferred way to use kzalloc? I have seen two ways under
>drivers/regulator/.
>
>1-
>
>struct my_regulator_info *info = NULL;
>
>info = kzalloc(sizeof(struct my_regulator_info), GFP_KERNEL);
>
>2-
>
>struct my_regulator_info *info;
>
>info = kzalloc(sizeof(*info), GFP_KERNEL);
Documentation/CodingStyle - Chapter 14: Allocating memory:
[...]
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.
Casting the return value which is a void pointer is redundant. The conversion
from void pointer to any other pointer type is guaranteed by the C programming
language.
Cheers, Hagen
prev parent reply other threads:[~2011-05-03 21:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-03 21:54 regulators: kzalloc doubt Thiago Farina
2011-05-03 21:58 ` Hagen Paul Pfeifer [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=20110503215828.GJ5352@nuttenaction \
--to=hagen@jauu.net \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lrg@slimlogic.co.uk \
--cc=tfransosi@gmail.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