The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] mtd: spi-nor: scope the exclusive RWW lock
@ 2026-08-09  8:42 Runyu Xiao
  2026-08-10  8:25 ` Michael Walle
  0 siblings, 1 reply; 13+ messages in thread
From: Runyu Xiao @ 2026-08-09  8:42 UTC (permalink / raw)
  To: tudor.ambarus
  Cc: pratyush, mwalle, miquel.raynal, richard, vigneshr, linux-mtd,
	linux-kernel, runyu.xiao, jianhao.xu, stable

spi_nor_rww_start_exclusive() is used as a wait_event_killable()
condition. The raw mutex_lock() leaves nor->lock held when the busy
condition returns false, so the waiter can block the active operation that
must clear the RWW state.

Use the same scoped mutex guard as the other RWW start helpers so the
mutex is released on both the busy and successful condition paths. The
state flags remain the handoff to the caller, while
spi_nor_rww_end_exclusive() continues
to acquire the mutex when clearing them.

The change was checked by comparing the original and patched source.

A source-level check of the original wait condition found that it takes
`nor->lock` and returns false while an RWW operation is still active. The
patched source was checked for a scoped mutex guard that releases
`nor->lock` before the wait condition returns. A user-space pthread model
held `nor->lock` on the false-condition path and showed that the
operation-ending path then blocks when it needs the same mutex. No live
SPI-NOR test was run.

Fixes: 03e7bb864d9a ("mtd: spi-nor: use scope-based mutex cleanup helpers")
Cc: stable@vger.kernel.org
Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
---
 drivers/mtd/spi-nor/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index ccf4396cdcd0..8bc117b46e02 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1310,7 +1310,7 @@ static bool spi_nor_rww_start_exclusive(struct spi_nor *nor)
 {
 	struct spi_nor_rww *rww = &nor->rww;
 
-	mutex_lock(&nor->lock);
+	guard(mutex)(&nor->lock);
 
 	if (rww->ongoing_io || rww->ongoing_rd || rww->ongoing_pe)
 		return false;
-- 
2.34.1

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

end of thread, other threads:[~2026-08-11 15:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-09  8:42 [PATCH] mtd: spi-nor: scope the exclusive RWW lock Runyu Xiao
2026-08-10  8:25 ` Michael Walle
2026-08-10 12:47   ` Miquel Raynal
2026-08-11  4:13   ` [PATCH v2] " Runyu Xiao
2026-08-11  7:51     ` Miquel Raynal
2026-08-11  8:31     ` [PATCH v3] mtd: spi-nor: use guard() in spi_nor_rww_start_exclusive Runyu Xiao
2026-08-11  8:41       ` Miquel Raynal
2026-08-11 10:11       ` Tudor Ambarus
2026-08-11 10:42         ` Tudor Ambarus
2026-08-11 14:36           ` Miquel Raynal
2026-08-11 15:38             ` Miquel Raynal
2026-08-11  8:50     ` [PATCH v2] mtd: spi-nor: scope the exclusive RWW lock Michael Walle
2026-08-11 10:05   ` [PATCH] " Tudor Ambarus

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