From mboxrd@z Thu Jan 1 00:00:00 1970 From: Albert ARIBAUD Date: Wed, 12 Feb 2014 18:58:37 +0100 Subject: [U-Boot] [PATCH] part_efi: fix protective_mbr struct allocation In-Reply-To: References: <1392216053-10344-1-git-send-email-hector.palacios@digi.com> <20140212173329.057a0c87@lilith> Message-ID: <20140212185837.153dd8df@lilith> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Fabio, On Wed, 12 Feb 2014 15:33:17 -0200, Fabio Estevam wrote: > Hi Albert, > > On Wed, Feb 12, 2014 at 2:33 PM, Albert ARIBAUD > 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." I still don't like it, but it makes sense indeed. > Regards, > > Fabio Estevam Amicalement, -- Albert.