From patchwork Fri Nov 13 13:25:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Longchamp X-Patchwork-Id: 544301 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 352691413FE for ; Sat, 14 Nov 2015 00:34:33 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2AD094BB23; Fri, 13 Nov 2015 14:34:23 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bVKRW3-87OKX; Fri, 13 Nov 2015 14:34:23 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8F3F54BB0A; Fri, 13 Nov 2015 14:34:10 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4C17A4BAB7 for ; Fri, 13 Nov 2015 14:34:03 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qxIi_pXvNr3H for ; Fri, 13 Nov 2015 14:34:03 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-de.keymile.com (mail-de.keymile.com [195.8.104.250]) by theia.denx.de (Postfix) with ESMTPS id 21D494BAB0 for ; Fri, 13 Nov 2015 14:34:01 +0100 (CET) From: Valentin Longchamp To: u-boot@lists.denx.de, Jagan Teki , Heiko Schocher , Simon Glass Date: Fri, 13 Nov 2015 14:25:54 +0100 Message-Id: <1447421155-13084-3-git-send-email-valentin.longchamp@keymile.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1447421155-13084-1-git-send-email-valentin.longchamp@keymile.com> References: <1447421155-13084-1-git-send-email-valentin.longchamp@keymile.com> Received: from mailrelay by mail-de.keymile.com Cc: Valentin Longchamp , Holger Brunck Subject: [U-Boot] [PATCH v3 2/3] env_sf: generalize call to spi_flash_free after accesses X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Some board require spi_flash_free to be called after all the accesses, in order, for instance, to restore the pin multiplexing configuration in the case where the SPI pins are multiplexed. This was done only in env_relocate_spec and not in saveenv. saveenv is thus changed in order to have the same behavior as env_relocate_spec. Since the static env_flash variable will be NULL after every function call, it is thus removed and its functionality is replaced by a systematic call to spi_flash_probe at the start of both env_relocate_spec and saveenv. Signed-off-by: Valentin Longchamp --- Changes in v3: - Rebased on v2015.10 Changes in v2: None common/env_sf.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/common/env_sf.c b/common/env_sf.c index 9409831..19fcbd3 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -52,14 +52,11 @@ int saveenv(void) u32 saved_size, saved_offset, sector = 1; int ret; + env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, + CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); if (!env_flash) { - env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, - CONFIG_ENV_SPI_CS, - CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); - if (!env_flash) { - set_default_env("!spi_flash_probe() failed"); - return 1; - } + set_default_env("!spi_flash_probe() failed"); + return 1; } ret = env_export(&env_new); @@ -131,6 +128,9 @@ int saveenv(void) if (saved_buffer) free(saved_buffer); + spi_flash_free(env_flash); + env_flash = NULL; + return ret; } @@ -228,14 +228,11 @@ int saveenv(void) int ret = 1; env_t env_new; + env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, + CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); if (!env_flash) { - env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, - CONFIG_ENV_SPI_CS, - CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); - if (!env_flash) { - set_default_env("!spi_flash_probe() failed"); - return 1; - } + set_default_env("!spi_flash_probe() failed"); + return 1; } /* Is the sector larger than the env (i.e. embedded) */ @@ -288,6 +285,9 @@ int saveenv(void) if (saved_buffer) free(saved_buffer); + spi_flash_free(env_flash); + env_flash = NULL; + return ret; }