]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
bloblist: refactor of bloblist_reloc()
authorRaymond Mao <raymond.mao@linaro.org>
Sat, 3 Feb 2024 16:36:22 +0000 (08:36 -0800)
committerTom Rini <trini@konsulko.com>
Thu, 29 Feb 2024 14:24:22 +0000 (09:24 -0500)
The current bloblist pointer and size can be retrieved from global
data, so we don't need to pass them from the function arguments.
This change also help to remove all external access of gd->bloblist
outside of bloblist module.

Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
common/bloblist.c
common/board_f.c
include/bloblist.h
test/bloblist.c

index 26b0ba33b11d7ae631b04ec018bfe7ce7fedc5c3..c2fd07575fb0b9dbcb31ecd638e40cf5c4491ecf 100644 (file)
@@ -472,13 +472,19 @@ void bloblist_show_list(void)
        }
 }
 
-void bloblist_reloc(void *to, uint to_size, void *from, uint from_size)
+int bloblist_reloc(void *to, uint to_size)
 {
        struct bloblist_hdr *hdr;
 
-       memcpy(to, from, from_size);
+       if (to_size < gd->bloblist->total_size)
+               return -ENOSPC;
+
+       memcpy(to, gd->bloblist, gd->bloblist->total_size);
        hdr = to;
        hdr->total_size = to_size;
+       gd->bloblist = to;
+
+       return 0;
 }
 
 int bloblist_init(void)
index 442b8349d088f47f0dafd7724c64d8dbe07d9546..7e3136910282835df7a897005934537000e542ce 100644 (file)
@@ -706,13 +706,10 @@ static int reloc_bloblist(void)
                return 0;
        }
        if (gd->new_bloblist) {
-               int size = CONFIG_BLOBLIST_SIZE;
-
                debug("Copying bloblist from %p to %p, size %x\n",
-                     gd->bloblist, gd->new_bloblist, size);
-               bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC,
-                              gd->bloblist, size);
-               gd->bloblist = gd->new_bloblist;
+                     gd->bloblist, gd->new_bloblist, gd->bloblist->total_size);
+               return bloblist_reloc(gd->new_bloblist,
+                                     CONFIG_BLOBLIST_SIZE_RELOC);
        }
 #endif
 
index cc78259e5a912d58b668c52f058d89306b6c7cbb..0ae079d62aa59006e381981e1bd58121dc0d1760 100644 (file)
@@ -426,11 +426,11 @@ const char *bloblist_tag_name(enum bloblist_tag_t tag);
  * bloblist_reloc() - Relocate the bloblist and optionally resize it
  *
  * @to: Pointer to new bloblist location (must not overlap old location)
- * @to_size: New size for bloblist (must be larger than from_size)
- * @from: Pointer to bloblist to relocate
- * @from_size: Size of bloblist to relocate
+ * @to_size: New size for bloblist
+ * Return: 0 if OK, -ENOSPC if the new size is small than the bloblist total
+ *        size.
  */
-void bloblist_reloc(void *to, uint to_size, void *from, uint from_size);
+int bloblist_reloc(void *to, uint to_size);
 
 /**
  * bloblist_init() - Init the bloblist system with a single bloblist
index 7dab9addf828b0f176aba41ab65584ab782b9a2b..1c60bbac36c3a8e05de3cb36ef86732102899846 100644 (file)
@@ -376,13 +376,12 @@ static int bloblist_test_reloc(struct unit_test_state *uts)
 {
        const uint large_size = TEST_BLOBLIST_SIZE;
        const uint small_size = 0x20;
-       void *old_ptr, *new_ptr;
+       void *new_ptr;
        void *blob1, *blob2;
        ulong new_addr;
        ulong new_size;
 
        ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0));
-       old_ptr = map_sysmem(TEST_ADDR, TEST_BLOBLIST_SIZE);
 
        /* Add one blob and then one that won't fit */
        blob1 = bloblist_add(TEST_TAG, small_size, 0);
@@ -394,8 +393,7 @@ static int bloblist_test_reloc(struct unit_test_state *uts)
        new_addr = TEST_ADDR + TEST_BLOBLIST_SIZE;
        new_size = TEST_BLOBLIST_SIZE + 0x100;
        new_ptr = map_sysmem(new_addr, TEST_BLOBLIST_SIZE);
-       bloblist_reloc(new_ptr, new_size, old_ptr, TEST_BLOBLIST_SIZE);
-       gd->bloblist = new_ptr;
+       ut_assertok(bloblist_reloc(new_ptr, new_size));
 
        /* Check the old blob is there and that we can now add the bigger one */
        ut_assertnonnull(bloblist_find(TEST_TAG, small_size));