Linux SPI subsystem development
 help / color / mirror / Atom feed
* [PATCH v2 0/2] spi: unoptimize message when queuing it fails
@ 2026-11-03 22:47 Joseph CT Chan
  2026-11-03 22:47 ` [PATCH v2 1/2] " Joseph CT Chan
  2026-11-03 22:47 ` [PATCH v2 2/2] spi: add KUnit tests for message optimize state on queue errors Joseph CT Chan
  0 siblings, 2 replies; 4+ messages in thread
From: Joseph CT Chan @ 2026-11-03 22:47 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, David Lechner, Bart Van Assche, Joseph CT Chan

From: Joseph CT Chan <josephctchan@google.com>

Hi Mark,

spi_async() and spi_sync() optimize a message before they queue it. If
queuing fails, the message is never finalized, so the split transfers
and the controller's optimize state leak and the message stays marked
as optimized. This happens with -EBUSY while another device holds
spi_bus_lock() (for example mmc_spi), with a stopped queue, and with an
error from a legacy transfer() callback. Patch 1 unoptimizes the message
on those error paths, and patch 2 adds KUnit tests for them.

Tested with KUnit on ARCH=um: all 7 cases pass with patch 1, and the 3
queue error cases fail without it. Not tested on hardware.

Changes in v2:
- Split out of the v1 14-patch series, as David suggested.
- Patch 1: added David's Reviewed-by.
- Patch 2: inject errors through the fake controller's transfer()
  callback instead of mem_ops, use designated initializers, and trim
  the comments.
- Moved the AI assistance note from an Assisted-by tag into the commit message.

v1: https://lore.kernel.org/all/20261102163023.2574632-1-jctchan@gmail.com/

The spi-mux, spi-ti-qspi and lock context series I am sending
separately are based on this one.

Walkthrough of the bug and the tests:
https://gist.github.com/joectchan/9a14b5e6facb75058ebc5a6ff1757131

Please consider this patch series for the next merge window.

Thanks,
Joseph

Joseph CT Chan (2):
  spi: unoptimize message when queuing it fails
  spi: add KUnit tests for message optimize state on queue errors

 drivers/spi/Kconfig                |  13 ++
 drivers/spi/Makefile               |   1 +
 drivers/spi/spi.c                  |   7 +
 drivers/spi/tests/.kunitconfig     |   4 +
 drivers/spi/tests/Makefile         |   1 +
 drivers/spi/tests/spi-core-kunit.c | 262 +++++++++++++++++++++++++++++
 6 files changed, 288 insertions(+)
 create mode 100644 drivers/spi/tests/.kunitconfig
 create mode 100644 drivers/spi/tests/spi-core-kunit.c


base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
-- 
2.56.0.385.gac671c819a-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-09 12:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-03 22:47 [PATCH v2 0/2] spi: unoptimize message when queuing it fails Joseph CT Chan
2026-11-03 22:47 ` [PATCH v2 1/2] " Joseph CT Chan
2026-11-03 22:47 ` [PATCH v2 2/2] spi: add KUnit tests for message optimize state on queue errors Joseph CT Chan
2026-11-09 12:21   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox