From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simon Glass Date: Sun, 9 Jul 2017 14:52:57 -0600 Subject: [U-Boot] [PATCH 14/30] env: common: Factor out the common env_valid check In-Reply-To: <20170709205313.116174-1-sjg@chromium.org> References: <20170709205313.116174-1-sjg@chromium.org> Message-ID: <20170709205313.116174-15-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de The check for gd->env_valid is used in both the 'if' and 'else' part of env_get_char(). Move it into that function instead for simplicity. Drop that code from the two leaf functions. Signed-off-by: Simon Glass --- env/common.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/env/common.c b/env/common.c index ce6b5f927a..10c4e134f4 100644 --- a/env/common.c +++ b/env/common.c @@ -34,25 +34,20 @@ __weak uchar env_get_char_spec(int index) static uchar env_get_char_init(int index) { - /* if crc was bad, use the default environment */ - if (gd->env_valid) - return env_get_char_spec(index); - else - return default_environment[index]; + return env_get_char_spec(index); } static uchar env_get_char_memory(int index) { - if (gd->env_valid) - return *(uchar *)(gd->env_addr + index); - else - return default_environment[index]; + return *(uchar *)(gd->env_addr + index); } uchar env_get_char(int index) { - /* if relocated to RAM */ - if (gd->flags & GD_FLG_RELOC) + /* if env is not set up, or crc was bad, use the default environment */ + if (!gd->env_valid) + return default_environment[index]; + else if (gd->flags & GD_FLG_RELOC) /* if relocated to RAM */ return env_get_char_memory(index); else return env_get_char_init(index); -- 2.13.2.725.g09c95d1e9-goog