cbfs: Return the error code from file_cbfs_init()
authorSimon Glass <sjg@chromium.org>
Sun, 24 May 2020 23:38:21 +0000 (17:38 -0600)
committerBin Meng <bmeng.cn@gmail.com>
Wed, 27 May 2020 06:40:09 +0000 (14:40 +0800)
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.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
cmd/cbfs.c
fs/cbfs/cbfs.c
include/cbfs.h

index 8e91d4bb8c2e9db805f535ed10381563b19072c4..10c2c929c37489d493ba6602eefd56f6172a5b3d 100644 (file)
@@ -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;
        }
index dc9789fcb8607126b09b108db2281c816af52c4f..73fe3b3624ca536219691b4e59790bf246ec18b0 100644 (file)
@@ -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)
index 07bbcfd2cff7a1b1e941789cea4f0c3c6cc0844f..962b3e848b36f4ecd1fb6cbfe92e4a1fba99254d 100644 (file)
@@ -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.