public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* regulators: kzalloc doubt
@ 2011-05-03 21:54 Thiago Farina
  2011-05-03 21:58 ` Hagen Paul Pfeifer
  0 siblings, 1 reply; 2+ messages in thread
From: Thiago Farina @ 2011-05-03 21:54 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, linux list

Hi guys,

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);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: regulators: kzalloc doubt
  2011-05-03 21:54 regulators: kzalloc doubt Thiago Farina
@ 2011-05-03 21:58 ` Hagen Paul Pfeifer
  0 siblings, 0 replies; 2+ messages in thread
From: Hagen Paul Pfeifer @ 2011-05-03 21:58 UTC (permalink / raw)
  To: Thiago Farina; +Cc: Mark Brown, Liam Girdwood, linux list

* 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-05-03 21:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-03 21:54 regulators: kzalloc doubt Thiago Farina
2011-05-03 21:58 ` Hagen Paul Pfeifer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox