[U-Boot] [PATCH v3 3/3] mmc: Protect `mmc_initialize` from initilizing mmc multiple times

Daniel Kochmański dkochmanski at turtle-solutions.eu
Fri May 29 16:55:43 CEST 2015


`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 at turtle-solutions.eu>
CC: Roy Spliet <r.spliet at ultimaker.com>
Cc: Ian Campbell <ijc at hellion.org.uk>
Cc: Hans De Goede <hdegoede at redhat.com>
CC: Pantelis Antoniou <panto at antoniou-consulting.com>
---
 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;
 
-- 
2.4.1



More information about the U-Boot mailing list