Linux SPI subsystem development
 help / color / mirror / Atom feed
From: Joseph CT Chan <jctchan@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, David Lechner <dlechner@baylibre.com>,
	Bart Van Assche <bvanassche@acm.org>,
	Joseph CT Chan <josephctchan@google.com>
Subject: [PATCH v2 0/2] spi: unoptimize message when queuing it fails
Date: Tue,  3 Nov 2026 22:47:51 +0000	[thread overview]
Message-ID: <20261103224753.3610049-1-jctchan@gmail.com> (raw)

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


             reply	other threads:[~2026-11-03 22:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 22:47 Joseph CT Chan [this message]
2026-11-03 22:47 ` [PATCH v2 1/2] spi: unoptimize message when queuing it fails 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

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=20261103224753.3610049-1-jctchan@gmail.com \
    --to=jctchan@gmail.com \
    --cc=broonie@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=dlechner@baylibre.com \
    --cc=josephctchan@google.com \
    --cc=linux-spi@vger.kernel.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