public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 3/3] mmc: Protect `mmc_initialize` from initilizing mmc multiple times
Date: Sat, 06 Jun 2015 11:53:09 +0200	[thread overview]
Message-ID: <5572C305.7030005@redhat.com> (raw)
In-Reply-To: <1432911343-8357-3-git-send-email-dkochmanski@turtle-solutions.eu>

Hi,

On 29-05-15 16:55, Daniel Kochma?ski wrote:
> `mmc_initialize` might be called from various places and initializing
> list head of `mmc_devices` can lead to memory leaks.
>
> Signed-off-by: Daniel Kochma?ski <dkochmanski@turtle-solutions.eu>
> CC: Roy Spliet <r.spliet@ultimaker.com>
> Cc: Ian Campbell <ijc@hellion.org.uk>
> Cc: Hans De Goede <hdegoede@redhat.com>
> CC: Pantelis Antoniou <panto@antoniou-consulting.com>

Thanks I've merged this one into u-boot-sunxi/next, for inclusion
into u-boot v2015.10, I've fixed a few typos in the commit message
and clarified the commit message a bit.

Pantelis, since this is an mmc patch may we have your ack for this
one please? It is a dep for some sunxi changes so it is probably
easiest if I just merge it through the sunxi tree.

Some background, we are adding support for booting from nand,
and as such we need to make spl_boot_device() for sunxi
smarter. The sunxi BROM does not communicate where it has
loaded the SPL from, so we simply retrace it steps trying
mmc0 first and looking for a valid bootsignature there.

This means calling mmc_initialize() from spl_boot_device()
and if spl_boot_device() then finds a boot signature
and returns BOOT_DEVICE_MMC1, then later on
spl_mmc_load_image() will call mmc_initialize() a second
time, this patch protects against this second call and
turns the second call into a nop.

Regards,

Hans



> ---
>   drivers/mmc/mmc.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index 79e6fee..2959bde 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -1758,6 +1758,11 @@ static void do_preinit(void)
>
>   int mmc_initialize(bd_t *bis)
>   {
> +	static int initialized = 0;
> +	if (initialized)	/* Avoid initializing mmc multiple times */
> +		return 0;
> +	initialized = 1;
> +
>   	INIT_LIST_HEAD (&mmc_devices);
>   	cur_dev_num = 0;
>
>

  reply	other threads:[~2015-06-06  9:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-29 14:55 [U-Boot] [PATCH v3 1/3] sunxi: Create helper function veryfing valid boot signature on MMC Daniel Kochmański
2015-05-29 14:55 ` [U-Boot] [PATCH v3 2/3] sunxi/spl: Detect at runtime where from SPL was read Daniel Kochmański
2015-06-06 14:56   ` Hans de Goede
2015-05-29 14:55 ` [U-Boot] [PATCH v3 3/3] mmc: Protect `mmc_initialize` from initilizing mmc multiple times Daniel Kochmański
2015-06-06  9:53   ` Hans de Goede [this message]
2015-06-06 14:55 ` [U-Boot] [PATCH v3 1/3] sunxi: Create helper function veryfing valid boot signature on MMC Hans de Goede

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=5572C305.7030005@redhat.com \
    --to=hdegoede@redhat.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