From patchwork Sun May 24 23:38:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 246401 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Sun, 24 May 2020 17:38:21 -0600 Subject: [PATCH v4 10/13] cbfs: Return the error code from file_cbfs_init() In-Reply-To: <20200524233824.81043-1-sjg@chromium.org> References: <20200524233824.81043-1-sjg@chromium.org> Message-ID: <20200524173815.v4.10.I4f249ceb7d5fbca62870416ee8f6ef06bc7fdd2f@changeid> We may as well return the error code and use it directly in the command code. CBFS still uses its own error enum which we may be able to remove, but leave it for now. Reviewed-by: Bin Meng Signed-off-by: Simon Glass --- Changes in v4: None Changes in v3: None Changes in v2: None cmd/cbfs.c | 3 +-- fs/cbfs/cbfs.c | 23 +++++++++++++++-------- include/cbfs.h | 6 +++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/cmd/cbfs.c b/cmd/cbfs.c index 8e91d4bb8c..10c2c929c3 100644 --- a/cmd/cbfs.c +++ b/cmd/cbfs.c @@ -28,8 +28,7 @@ static int do_cbfs_init(struct cmd_tbl *cmdtp, int flag, int argc, return 1; } } - file_cbfs_init(end_of_rom); - if (cbfs_get_result() != CBFS_SUCCESS) { + if (file_cbfs_init(end_of_rom)) { printf("%s.\n", file_cbfs_error()); return 1; } diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index dc9789fcb8..73fe3b3624 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -253,19 +253,26 @@ static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base) return 0; } -static void cbfs_init(struct cbfs_priv *priv, ulong end_of_rom) +static int cbfs_init(struct cbfs_priv *priv, ulong end_of_rom) { - if (file_cbfs_load_header(priv, end_of_rom)) - return; + int ret; - file_cbfs_fill_cache(priv, priv->header.rom_size, priv->header.align); - if (priv->result == CBFS_SUCCESS) - priv->initialized = true; + ret = file_cbfs_load_header(priv, end_of_rom); + if (ret) + return ret; + + ret = file_cbfs_fill_cache(priv, priv->header.rom_size, + priv->header.align); + if (ret) + return ret; + priv->initialized = true; + + return 0; } -void file_cbfs_init(ulong end_of_rom) +int file_cbfs_init(ulong end_of_rom) { - cbfs_init(&cbfs_s, end_of_rom); + return cbfs_init(&cbfs_s, end_of_rom); } int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp) diff --git a/include/cbfs.h b/include/cbfs.h index 07bbcfd2cf..962b3e848b 100644 --- a/include/cbfs.h +++ b/include/cbfs.h @@ -98,10 +98,10 @@ enum cbfs_result cbfs_get_result(void); /** * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM. * - * @end_of_rom: Points to the end of the ROM the CBFS should be read - * from. + * @end_of_rom: Points to the end of the ROM the CBFS should be read from + * @return 0 if OK, -ve on error */ -void file_cbfs_init(ulong end_of_rom); +int file_cbfs_init(ulong end_of_rom); /** * file_cbfs_get_header() - Get the header structure for the current CBFS.