U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "João Loureiro" <joaofl@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: "Tom Rini" <trini@konsulko.com>, "Simon Glass" <sjg@chromium.org>,
	"João Loureiro" <joaofl@gmail.com>
Subject: [PATCH v5 1/3] test: dm: sf: Get the emulator attached to the flash slave
Date: Sat,  5 Sep 2026 12:24:29 +0200	[thread overview]
Message-ID: <20260905102431.426747-2-joaofl@gmail.com> (raw)
In-Reply-To: <20260615175118.53720-1-joaofl@gmail.com>

dm_test_spi_flash() picks up its SPI emulator with
uclass_first_device_err(UCLASS_SPI_EMUL), which assumes the sandbox SPI
flash emulator is the only device in that uclass. That holds today only
because the flash emulator is bound lazily, on the first transfer.

As soon as a second SPI emulator is described in the device tree it is
bound during the devicetree scan and so comes first in the uclass. The
test then hands a foreign device to sandbox_sf_set_block_protect(),
which casts its private data to struct sandbox_spi_flash and writes
past the end of it, corrupting the heap.

Ask for the emulator attached to this particular slave instead, which
is what the test means, and which stays correct however many SPI
emulators exist.

Signed-off-by: João Loureiro <joaofl@gmail.com>
---
 test/dm/sf.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/test/dm/sf.c b/test/dm/sf.c
index 3684d021709..0ec02ac694b 100644
--- a/test/dm/sf.c
+++ b/test/dm/sf.c
@@ -50,8 +50,13 @@ static int dm_test_spi_flash(struct unit_test_state *uts)
 	ut_assertok(spi_flash_read_dm(dev, 0, size, dst));
 	ut_asserteq_mem(src, dst, size);
 
-	/* Try the write-protect stuff */
-	ut_assertok(uclass_first_device_err(UCLASS_SPI_EMUL, &emul));
+	/*
+	 * Try the write-protect stuff. Ask for the emulator attached to this
+	 * particular slave rather than the first one in the uclass, since
+	 * other SPI emulators may be present.
+	 */
+	ut_assertok(sandbox_spi_get_emul(state_get_current(), dev->parent, dev,
+					 &emul));
 	ut_asserteq(0, spl_flash_get_sw_write_prot(dev));
 	sandbox_sf_set_block_protect(emul, 1);
 	ut_asserteq(1, spl_flash_get_sw_write_prot(dev));
-- 
2.55.0


  parent reply	other threads:[~2026-09-05 13:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04 11:38 [PATCH] SPI: Introduce initial EEPROM driver mode support Loureiro, Joao
2025-02-24 11:43 ` [PATCH] spi: Introduce initial eeprom " Loureiro, Joao
2025-03-04 17:47   ` Tom Rini
2025-03-05 12:26 ` [PATCH v2] spi: Introduce initial EEPROM " Loureiro, Joao
2026-06-10 22:11   ` [PATCH v3 0/2] " João Loureiro
2026-06-10 22:11     ` [PATCH v3 1/2] " João Loureiro
2026-06-10 22:12     ` [PATCH v3 2/2] sandbox: spi: Add SPI EEPROM emulator and DM test João Loureiro
2026-06-14 12:18       ` Simon Glass
2026-06-15 17:51     ` [PATCH v4 0/2] spi: Introduce initial EEPROM driver mode support João Loureiro
2026-06-15 17:51       ` [PATCH v4 1/2] " João Loureiro
2026-07-13 13:03         ` Simon Glass
2026-09-05 10:14           ` João Loureiro
2026-06-15 17:51       ` [PATCH v4 2/2] sandbox: spi: Add SPI EEPROM emulator and DM test João Loureiro
2026-09-05 10:24       ` [PATCH v5 0/3] spi: Introduce driver-model support for SPI EEPROMs João Loureiro
2026-09-10 14:30         ` Simon Glass
2026-09-05 10:24       ` João Loureiro [this message]
2026-09-05 10:24       ` [PATCH v5 2/3] spi: Introduce initial " João Loureiro
2026-09-05 10:24       ` [PATCH v5 3/3] sandbox: spi: Add SPI EEPROM emulator and DM test João Loureiro

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=20260905102431.426747-2-joaofl@gmail.com \
    --to=joaofl@gmail.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox