[U-Boot] [PATCH] part_efi: fix protective_mbr struct allocation

Fabio Estevam festevam at gmail.com
Wed Feb 12 18:33:17 CET 2014


Hi Albert,

On Wed, Feb 12, 2014 at 2:33 PM, Albert ARIBAUD
<albert.u.boot at aribaud.net> wrote:

>> What about:
>>
>> p_mbr = calloc(1, sizeof(*p_mbr)) ?
>
> I don't like the idea of setting p_mbr based on *p_mbr at a time where
> p_mbr is still undefined. I know that from a C standard perspective
> this is ok, but I'd rather simply not run any risk and pass sizeof
> the struct type, not a (non-existent) dereferenced 'value'.

At least in kernel this is the preferred way.

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

Regards,

Fabio Estevam


More information about the U-Boot mailing list