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>,
Conor Dooley <conor.dooley@microchip.com>,
Joseph CT Chan <josephctchan@google.com>
Subject: [PATCH v2 2/5] spi: Add lock context annotations for bus_lock_mutex
Date: Tue, 3 Nov 2026 22:55:19 +0000 [thread overview]
Message-ID: <20261103225522.3643901-3-jctchan@gmail.com> (raw)
In-Reply-To: <20261103225522.3643901-1-jctchan@gmail.com>
From: Bart Van Assche <bvanassche@acm.org>
Annotate spi_bus_lock() with __acquires(), spi_bus_unlock() with
__releases(), spi_sync_locked() and __spi_sync() with __must_hold(), and
spi_sync() with __must_not_hold() for bus_lock_mutex in
include/linux/spi/spi.h and drivers/spi/spi.c. Document exclusive SPI
bus lock ownership and enable static context analysis to verify locking
invariants across callers and the SPI core.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Joseph CT Chan <josephctchan@google.com>
---
drivers/spi/spi.c | 5 +++++
include/linux/spi/spi.h | 12 ++++++++----
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 85089b0ebf4b..01dfc25c1376 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -4959,6 +4959,7 @@ static void spi_complete(void *arg)
}
static int __spi_sync(struct spi_device *spi, struct spi_message *message)
+ __must_hold(&spi->controller->bus_lock_mutex)
{
DECLARE_COMPLETION_ONSTACK(done);
unsigned long flags;
@@ -5045,6 +5046,7 @@ static int __spi_sync(struct spi_device *spi, struct spi_message *message)
* Return: zero on success, else a negative error code.
*/
int spi_sync(struct spi_device *spi, struct spi_message *message)
+ __must_not_hold(&spi->controller->bus_lock_mutex)
{
int ret;
@@ -5073,6 +5075,7 @@ EXPORT_SYMBOL_GPL(spi_sync);
* Return: zero on success, else a negative error code.
*/
int spi_sync_locked(struct spi_device *spi, struct spi_message *message)
+ __must_hold(&spi->controller->bus_lock_mutex)
{
return __spi_sync(spi, message);
}
@@ -5094,6 +5097,7 @@ EXPORT_SYMBOL_GPL(spi_sync_locked);
* Return: always zero.
*/
int spi_bus_lock(struct spi_controller *ctlr)
+ __acquires(&ctlr->bus_lock_mutex)
{
unsigned long flags;
@@ -5123,6 +5127,7 @@ EXPORT_SYMBOL_GPL(spi_bus_lock);
* Return: always zero.
*/
int spi_bus_unlock(struct spi_controller *ctlr)
+ __releases(&ctlr->bus_lock_mutex)
{
ctlr->bus_lock_flag = 0;
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index fb4baa0d3398..553c32987c97 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -1497,10 +1497,14 @@ extern int spi_split_transfers_maxwords(struct spi_controller *ctlr,
* they will sleep uninterruptibly until the async transfer completes.
*/
-extern int spi_sync(struct spi_device *spi, struct spi_message *message);
-extern int spi_sync_locked(struct spi_device *spi, struct spi_message *message);
-extern int spi_bus_lock(struct spi_controller *ctlr);
-extern int spi_bus_unlock(struct spi_controller *ctlr);
+extern int spi_sync(struct spi_device *spi, struct spi_message *message)
+ __must_not_hold(&spi->controller->bus_lock_mutex);
+extern int spi_sync_locked(struct spi_device *spi, struct spi_message *message)
+ __must_hold(&spi->controller->bus_lock_mutex);
+extern int spi_bus_lock(struct spi_controller *ctlr)
+ __acquires(&ctlr->bus_lock_mutex);
+extern int spi_bus_unlock(struct spi_controller *ctlr)
+ __releases(&ctlr->bus_lock_mutex);
/**
* spi_sync_transfer - synchronous SPI data transfer
--
2.56.0.385.gac671c819a-goog
next prev parent reply other threads:[~2026-11-03 22:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 22:55 [PATCH v2 0/5] spi: lock context annotations Joseph CT Chan
2026-11-03 22:55 ` [PATCH v2 1/5] spi: Split spi_write_then_read() Joseph CT Chan
2026-11-03 22:55 ` Joseph CT Chan [this message]
2026-11-03 22:55 ` [PATCH v2 3/5] spi: spi-mem: Add lock context annotations Joseph CT Chan
2026-11-03 22:55 ` [PATCH v2 4/5] spi: microchip-core-qspi: " Joseph CT Chan
2026-11-03 22:55 ` [PATCH v2 5/5] spi: Enable lock context analysis Joseph CT Chan
2026-11-04 14:46 ` [PATCH v2 0/5] spi: lock context annotations Mark Brown
2026-11-05 4:03 ` Joseph CT Chan
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=20261103225522.3643901-3-jctchan@gmail.com \
--to=jctchan@gmail.com \
--cc=broonie@kernel.org \
--cc=bvanassche@acm.org \
--cc=conor.dooley@microchip.com \
--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