From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hans de Goede Date: Sat, 06 Jun 2015 11:53:09 +0200 Subject: [U-Boot] [PATCH v3 3/3] mmc: Protect `mmc_initialize` from initilizing mmc multiple times In-Reply-To: <1432911343-8357-3-git-send-email-dkochmanski@turtle-solutions.eu> References: <1432911343-8357-1-git-send-email-dkochmanski@turtle-solutions.eu> <1432911343-8357-3-git-send-email-dkochmanski@turtle-solutions.eu> Message-ID: <5572C305.7030005@redhat.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 > CC: Roy Spliet > Cc: Ian Campbell > Cc: Hans De Goede > CC: Pantelis Antoniou 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; > >