[PATCH] drivers: Conversions from kmalloc+memset to k(z|c)alloc.

Panagiotis Issaris takis at gna.org
Fri Jul 21 06:35:56 EDT 2006


Hi,

On vr, 2006-07-21 at 12:20 +0200, Jesper Juhl wrote:
> [snip]
> >  - better style of the size argument where correct,
> 
> Who says it's "better style" ?
Documentation/CodingStyle does :) (which in fact, I only noticed when I
was validating someone's remark that it would be a good idea to change
sizeof's)

"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."


> You can argue that   sizeof(type) is more readable.
> When reading the code you don't have to go lookup the type of ptr in
> sizeof(*ptr)  before you know what type the code is working with.


With friendly regards,
Takis




More information about the linux-pcmcia mailing list