public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Lukasz Majewski <l.majewski@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] part_efi: fix protective_mbr struct allocation
Date: Wed, 12 Feb 2014 16:55:58 +0100	[thread overview]
Message-ID: <20140212165558.100c71cb@amdc2363> (raw)
In-Reply-To: <1392216053-10344-1-git-send-email-hector.palacios@digi.com>

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 <hector.palacios@digi.com>
> ---
>  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

  parent reply	other threads:[~2014-02-12 15:55 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-12 14:40 [U-Boot] [PATCH] part_efi: fix protective_mbr struct allocation Hector Palacios
2014-02-12 14:43 ` Fabio Estevam
2014-02-12 16:33   ` Albert ARIBAUD
2014-02-12 17:33     ` Fabio Estevam
2014-02-12 17:58       ` Albert ARIBAUD
2014-02-12 15:55 ` Lukasz Majewski [this message]
2014-02-12 16:24   ` Palacios, Hector
2014-02-12 16:30     ` Albert ARIBAUD
2014-02-12 16:48       ` Palacios, Hector
2014-02-12 20:45         ` Lukasz Majewski
2014-02-13  2:23           ` Albert ARIBAUD
2014-02-19  8:19             ` Lukasz Majewski
2014-02-19 10:08               ` Albert ARIBAUD
2014-02-19 10:15                 ` Albert ARIBAUD
2014-02-19 12:52                   ` Palacios, Hector
2014-02-19 14:14                     ` Albert ARIBAUD
2014-02-19 14:25                       ` Lukasz Majewski
2014-02-19 14:38                         ` Albert ARIBAUD
2014-02-19 15:11                           ` Lukasz Majewski
2014-02-19 14:22               ` Tom Rini
2014-02-19 15:10                 ` Lukasz Majewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140212165558.100c71cb@amdc2363 \
    --to=l.majewski@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox