All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Simon Glass <sjg@chromium.org>
Subject: [PATCH 17/22] bloblist: Correct condition in bloblist_addrec()
Date: Mon,  5 Jul 2021 16:32:55 -0600	[thread overview]
Message-ID: <20210705223300.2139971-16-sjg@chromium.org> (raw)
In-Reply-To: <20210705223300.2139971-1-sjg@chromium.org>

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(-)

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[])
 {
-- 
2.32.0.93.g670b81a890-goog


  parent reply	other threads:[~2021-07-05 22:35 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-05 22:32 [PATCH 00/22] Various fixes and enhancements Simon Glass
2021-07-05 22:32 ` [PATCH 01/22] dm: core: Add logging for DM_SEQ_ALIAS Simon Glass
2021-07-05 22:32 ` [PATCH 02/22] dm: Support lzma in the flashmap Simon Glass
2021-07-05 22:32 ` [PATCH 03/22] test: Allow CONFIG_SPL_LOAD_FIT to be disabled Simon Glass
2021-07-05 22:32 ` [PATCH 04/22] test: Add DM_DMA " Simon Glass
2021-07-05 22:32 ` [PATCH 05/22] test: Avoid a build error with SPL Simon Glass
2021-07-05 22:32 ` [PATCH 06/22] Makefile: Avoid rebuilding .dtb files each time Simon Glass
2021-07-05 22:32 ` [PATCH 07/22] sandbox: Support executables for more phases Simon Glass
2021-07-05 22:32 ` [PATCH 08/22] sandbox: Add work-around for SDL2 display Simon Glass
2021-07-22  6:00   ` Heinrich Schuchardt
2021-07-22 13:28     ` Simon Glass
2021-07-05 22:32 ` [PATCH 09/22] sandbox: Use hinting with the display Simon Glass
2021-07-05 22:32 ` [PATCH 10/22] sandbox: Adjust the bloblist default address Simon Glass
2021-07-05 22:32 ` [PATCH 11/22] cros_ec: Allow reading the battery-charge state Simon Glass
2021-07-05 22:32 ` [PATCH 12/22] cros_ec: Drop cros_ec_entering_mode() Simon Glass
2021-07-05 22:32 ` [PATCH 13/22] cros_ec: Support the full-size vboot context Simon Glass
2021-07-05 22:32 ` [PATCH 14/22] cros_ec: Use standard calls for recovery-request checking Simon Glass
2021-07-05 22:32 ` [PATCH 15/22] bloblist: Support resizing a blob Simon Glass
2021-07-05 22:32 ` [PATCH 16/22] bloblist: Tidy up a few API comments Simon Glass
2021-07-05 22:32 ` Simon Glass [this message]
2021-07-05 22:32 ` [PATCH 18/22] image: Allow @ in node names when not using signatures Simon Glass
2021-07-17 20:40   ` Simon Glass
2021-07-05 22:32 ` [PATCH 19/22] spl: Provide more information on boot failure Simon Glass
2021-07-05 22:32 ` [PATCH 20/22] sandbox: mmc: Support fixed MMC devices Simon Glass
2021-07-06  1:12   ` Jaehoon Chung
2021-07-17 20:39   ` Simon Glass
2021-07-05 22:32 ` [PATCH 21/22] blk: Support iteration Simon Glass
2021-07-05 22:33 ` [PATCH 22/22] log: Allow padding of the function name Simon Glass
2021-07-17 20:39 ` Simon Glass
2021-07-17 20:39 ` [PATCH 21/22] blk: Support iteration Simon Glass
2021-07-17 20:39 ` [PATCH 19/22] spl: Provide more information on boot failure Simon Glass
2021-07-17 20:39 ` [PATCH 17/22] bloblist: Correct condition in bloblist_addrec() Simon Glass
2021-07-17 20:39 ` [PATCH 16/22] bloblist: Tidy up a few API comments Simon Glass
2021-07-17 20:39 ` [PATCH 15/22] bloblist: Support resizing a blob Simon Glass
2021-07-17 20:39 ` [PATCH 14/22] cros_ec: Use standard calls for recovery-request checking Simon Glass
2021-07-17 20:39 ` [PATCH 13/22] cros_ec: Support the full-size vboot context Simon Glass
2021-07-17 20:39 ` [PATCH 12/22] cros_ec: Drop cros_ec_entering_mode() Simon Glass
2021-07-17 20:39 ` [PATCH 11/22] cros_ec: Allow reading the battery-charge state Simon Glass
2021-07-17 20:39 ` [PATCH 10/22] sandbox: Adjust the bloblist default address Simon Glass
2021-07-17 20:39 ` [PATCH 09/22] sandbox: Use hinting with the display Simon Glass
2021-07-17 20:39 ` [PATCH 08/22] sandbox: Add work-around for SDL2 display Simon Glass
2021-07-17 20:39 ` [PATCH 07/22] sandbox: Support executables for more phases Simon Glass
2021-07-17 20:39 ` [PATCH 06/22] Makefile: Avoid rebuilding .dtb files each time Simon Glass
2021-07-18 13:34   ` Masahiro Yamada
2021-07-22  2:13     ` Simon Glass
2021-07-17 20:39 ` [PATCH 05/22] test: Avoid a build error with SPL Simon Glass
2021-07-17 20:39 ` [PATCH 04/22] test: Add DM_DMA to be disabled Simon Glass
2021-07-17 20:39 ` [PATCH 03/22] test: Allow CONFIG_SPL_LOAD_FIT " Simon Glass
2021-07-17 20:39 ` [PATCH 02/22] dm: Support lzma in the flashmap Simon Glass
2021-07-17 20:39 ` [PATCH 01/22] dm: core: Add logging for DM_SEQ_ALIAS Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210705223300.2139971-16-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.