lkml.org 
[lkml]   [2011]   [May]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: regulators: kzalloc doubt
* 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


\
 
 \ /
  Last update: 2011-05-04 00:01    [W:0.991 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site