From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lukasz Majewski Date: Wed, 12 Feb 2014 16:55:58 +0100 Subject: [U-Boot] [PATCH] part_efi: fix protective_mbr struct allocation In-Reply-To: <1392216053-10344-1-git-send-email-hector.palacios@digi.com> References: <1392216053-10344-1-git-send-email-hector.palacios@digi.com> Message-ID: <20140212165558.100c71cb@amdc2363> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Hector, > The calloc() call was allocating space for the sizeof the struct > pointer rather than for the struct contents. > > Signed-off-by: Hector Palacios > --- > disk/part_efi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/disk/part_efi.c b/disk/part_efi.c > index 5dfaf490c89a..7fabec059d7a 100644 > --- a/disk/part_efi.c > +++ b/disk/part_efi.c > @@ -232,7 +232,7 @@ static int set_protective_mbr(block_dev_desc_t > *dev_desc) legacy_mbr *p_mbr; > > /* Setup the Protective MBR */ > - p_mbr = calloc(1, sizeof(p_mbr)); > + p_mbr = calloc(1, sizeof(legacy_mbr)); Thanks for spotting the error. _Damn_ However, this is not enough. Since this buffer is passed to mmc for writing (and some targets may use cache) the legacy_mbr shall be defined as: ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, p_mbr, sizeof(legacy_mbr)); memset(p_mbr, 0, sizeof(legacy_mbr)); Would you like to prepare v2 of this patch or shall I prepare the fix? > if (p_mbr == NULL) { > printf("%s: calloc failed!\n", __func__); > return -1; -- Best regards, Lukasz Majewski Samsung R&D Institute Poland (SRPOL) | Linux Platform Group