diff mbox series

[17/22] bloblist: Correct condition in bloblist_addrec()

Message ID 20210705223300.2139971-16-sjg@chromium.org
State Accepted
Commit 1f618d528e234d2b7b0047750284dd531f5d718f
Delegated to: Simon Glass
Headers show
Series Various fixes and enhancements | expand

Commit Message

Simon Glass July 5, 2021, 10:32 p.m. UTC
It is possible to add a blob that ends at the end of the bloblist, but at
present this is not supported. Fix it and add a regression test for this
case.

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

 common/bloblist.c |  2 +-
 test/bloblist.c   | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

Comments

Simon Glass July 17, 2021, 8:39 p.m. UTC | #1
It is possible to add a blob that ends at the end of the bloblist, but at
present this is not supported. Fix it and add a regression test for this
case.

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

 common/bloblist.c |  2 +-
 test/bloblist.c   | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/common/bloblist.c b/common/bloblist.c
index bb49ecab92e..1290fff8504 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -118,7 +118,7 @@  static int bloblist_addrec(uint tag, int size, int align,
 	/* Calculate the new allocated total */
 	new_alloced = data_start + ALIGN(size, align);
 
-	if (new_alloced >= hdr->size) {
+	if (new_alloced > hdr->size) {
 		log(LOGC_BLOBLIST, LOGL_ERR,
 		    "Failed to allocate %x bytes size=%x, need size=%x\n",
 		    size, hdr->size, new_alloced);
diff --git a/test/bloblist.c b/test/bloblist.c
index 345eb181fff..4104e6a92f6 100644
--- a/test/bloblist.c
+++ b/test/bloblist.c
@@ -576,6 +576,29 @@  static int bloblist_test_resize_last(struct unit_test_state *uts)
 }
 BLOBLIST_TEST(bloblist_test_resize_last, 0);
 
+/* Check a completely full bloblist */
+static int bloblist_test_blob_maxsize(struct unit_test_state *uts)
+{
+	void *ptr;
+	int size;
+
+	/* At the start there should be no records */
+	clear_bloblist();
+	ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0));
+
+	/* Add a blob that takes up all space */
+	size = TEST_BLOBLIST_SIZE - sizeof(struct bloblist_hdr) -
+		sizeof(struct bloblist_rec);
+	ptr = bloblist_add(TEST_TAG, size, 0);
+	ut_assertnonnull(ptr);
+
+	ptr = bloblist_add(TEST_TAG, size + 1, 0);
+	ut_assertnull(ptr);
+
+	return 0;
+}
+BLOBLIST_TEST(bloblist_test_blob_maxsize, 0);
+
 int do_ut_bloblist(struct cmd_tbl *cmdtp, int flag, int argc,
 		   char *const argv[])
 {