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

From: Panagiotis Issaris
Date: Fri Jul 21 2006 - 06:34:18 EST


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

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/