This has become quite complicated now, with much of the code indented,
gd->bloblist set in multiple places, multiple error paths and ret set to
different things in different places.

Make an attempt to simplify it, without changing functionality.

Signed-off-by: Simon Glass <s...@chromium.org>
---

 common/bloblist.c | 67 ++++++++++++++++++++++-------------------------
 1 file changed, 31 insertions(+), 36 deletions(-)

diff --git a/common/bloblist.c b/common/bloblist.c
index 6e4f020d7c4..135fb149626 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -513,48 +513,43 @@ int __weak xferlist_from_boot_arg(ulong __always_unused 
*addr)
 int bloblist_init(void)
 {
        bool fixed = IS_ENABLED(CONFIG_BLOBLIST_FIXED);
-       int ret = 0;
+       int ret = -ENOENT;
        ulong addr = 0, size;
 
-       /* Check if a valid transfer list passed in */
-       if (!xferlist_from_boot_arg(&addr)) {
-               size = bloblist_get_total_size();
-       } else {
-               /*
-                * If U-Boot is not in the first phase, an existing bloblist 
must
-                * be at a fixed address.
-                */
-               bool from_addr = fixed && !xpl_is_first_phase();
+       /*
+        * If U-Boot is not in the first phase, an existing bloblist must be
+        * at a fixed address.
+        */
+       bool from_addr = fixed && !xpl_is_first_phase();
+       /*
+        * If U-Boot is in the first phase then an arch custom routine should
+        * install the bloblist passed from previous loader to this fixed
+        * address.
+        */
+       bool from_boot_arg = fixed && xpl_is_first_phase();
 
+       if (xpl_prev_phase() == PHASE_TPL && !IS_ENABLED(CONFIG_TPL_BLOBLIST))
+               from_addr = false;
+       if (fixed)
+               addr = IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED,
+                                     CONFIG_BLOBLIST_ADDR);
+       size = CONFIG_BLOBLIST_SIZE;
+
+       if (from_boot_arg) {
+               ret = xferlist_from_boot_arg(&addr);
                /*
                 * If Firmware Handoff is mandatory but no transfer list is
                 * observed, report it as an error.
                 */
-               if (IS_ENABLED(CONFIG_BLOBLIST_PASSAGE_MANDATORY))
+               if (ret && IS_ENABLED(CONFIG_BLOBLIST_PASSAGE_MANDATORY))
                        return -ENOENT;
-
-               ret = -ENOENT;
-
-               if (xpl_prev_phase() == PHASE_TPL &&
-                   !IS_ENABLED(CONFIG_TPL_BLOBLIST))
-                       from_addr = false;
-               if (fixed)
-                       addr = IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED,
-                                             CONFIG_BLOBLIST_ADDR);
-               size = CONFIG_BLOBLIST_SIZE;
-
-               if (from_addr)
-                       ret = bloblist_check(addr, size);
-
-               if (ret)
-                       log_warning("Bloblist at %lx not found (err=%d)\n",
-                                   addr, ret);
-               else
-                       /* Get the real size */
-                       size = gd->bloblist->total_size;
+       } else if (from_addr) {
+               ret = bloblist_check(addr, size);
        }
 
        if (ret) {
+               log_warning("Bloblist at %lx not found (err=%d)\n", addr, ret);
+
                /*
                 * If we don't have a bloblist from a fixed address, or the one
                 * in the fixed address is not valid. we must allocate the
@@ -573,13 +568,15 @@ int bloblist_init(void)
                log_debug("Creating new bloblist size %lx at %lx\n", size,
                          addr);
                ret = bloblist_new(addr, size, 0, 0);
+               if (ret)
+                       return log_msg_ret("ini", ret);
        } else {
+               /* Get the real size */
+               size = gd->bloblist->total_size;
                log_debug("Found existing bloblist size %lx at %lx\n", size,
                          addr);
        }
 
-       if (ret)
-               return log_msg_ret("ini", ret);
        gd->flags |= GD_FLG_BLOBLIST_READY;
 
 #ifdef DEBUG
@@ -620,10 +617,8 @@ int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong 
rsig, ulong xlist)
        if (ret)
                return ret;
 
-       if (rfdt != (ulong)bloblist_find(BLOBLISTT_CONTROL_FDT, 0)) {
-               gd->bloblist = NULL;  /* Reset the gd bloblist pointer */
+       if (rfdt != (ulong)bloblist_find(BLOBLISTT_CONTROL_FDT, 0))
                return -EIO;
-       }
 
        return 0;
 }
-- 
2.43.0

Reply via email to