From patchwork Mon Oct 30 14:07:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Faiz Abbas X-Patchwork-Id: 832063 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="lNANWyMD"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yQbrq5MVCz9t2M for ; Tue, 31 Oct 2017 01:07:07 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 825C0C21D75; Mon, 30 Oct 2017 14:07:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 19E2AC21C57; Mon, 30 Oct 2017 14:07:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7AC86C21C57; Mon, 30 Oct 2017 14:06:59 +0000 (UTC) Received: from lelnx193.ext.ti.com (lelnx193.ext.ti.com [198.47.27.77]) by lists.denx.de (Postfix) with ESMTPS id 4CCCEC21C4F for ; Mon, 30 Oct 2017 14:06:56 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx193.ext.ti.com (8.15.1/8.15.1) with ESMTP id v9UE6s8e022375; Mon, 30 Oct 2017 09:06:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1509372414; bh=ZtYBaME59XjISoSc5i/lPSka+AgClcEj1QPcfYrMsK8=; h=From:Subject:To:CC:Date; b=lNANWyMDckV1CL7lKXYivn4ncdgbItDG0H2DW3G0sw/vkAjhH1LaIA/ofLhf5wk/T xxu39QxzwX7ahKgNZNcXyD4ZYvBfI0OpRTL9Gi84lDSwqr49trZzcVBDkE0BUpuDOM PJraNheYw/3ufFd7DsoLjw4sw4UGISa3+D/8bJkg= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v9UE6sJq019975; Mon, 30 Oct 2017 09:06:54 -0500 Received: from DLEE110.ent.ti.com (157.170.170.21) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.845.34; Mon, 30 Oct 2017 09:06:53 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.845.34 via Frontend Transport; Mon, 30 Oct 2017 09:06:53 -0500 Received: from [172.24.190.215] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v9UE6pj1010862; Mon, 30 Oct 2017 09:06:52 -0500 From: Faiz Abbas To: Message-ID: Date: Mon, 30 Oct 2017 19:37:15 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Language: en-US X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: Tom Rini , dkochmanski@turtle-solutions.eu, hdegoede@redhat.com Subject: [U-Boot] Problem with initialize in mmc_initialize in mmc.c X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Hi, The variable *initialized* in mmc_initialize() is declared as static and initialised to 0 in the following commit. This makes the compiler put it in the .bss section of the image. commit 1b26bab12e85e8b0d382d6775e40d14445249574 Author: Daniel Kochmański Date: Fri May 29 16:55:43 2015 +0200 mmc: Protect `mmc_initialize` from initialising mmc multiple times `mmc_initialize` might be called multiple times leading to the mmc-controllers being initialised twice, and initialising the `mmc_devices` list head twice which may lead to memory leaks. Signed-off-by: Daniel Kochmański CC: Roy Spliet Cc: Ian Campbell CC: Pantelis Antoniou Acked-by: Hans de Goede Signed-off-by: Hans de Goede .bss should not be accessed in u-boot before relocation because it overlaps with fdt and writing to variables in .bss can corrupt the fdt. MMC can be probed before relocation if it contains the u-boot environment. Therefore, I tried to move this variable to the .data section by static int initialized __attribute__((section(".data"))); When *initialized* was a part of .bss it was getting re-initilized to 0 as a part of relocation. Therefore, mmc was getting probed again successfully after relocation with new addresses for mmc devices. Now when *initialized* is not a part of .bss, it holds its value across relocation and a second call to mmc_initialize() returns without doing anything. However, the *mmc_devices* list containing pointers to the older locations of mmc devices is not refreshed and thus mmc devices fail to enumerate. So *initialized* is a problem whether it is in .data or .bss. I am not sure how to fix this. Any help is appreciated. Thanks, Faiz diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index da47037..f12546a 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1762,6 +1762,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;