From: sashiko-bot@kernel.org
To: "Itai Handler" <itai.handler@gmail.com>,
mwalle@kernel.org, pratyush@kernel.org
Cc: linux-kernel@vger.kernel.org, vigneshr@ti.com, richard@nod.at,
miquel.raynal@bootlin.com, linux-mtd@lists.infradead.org,
stable@vger.kernel.org, takahiro.kuwano@infineon.com
Subject: Re: [PATCH v2 2/3] mtd: spi-nor: take the flash lock in spi_nor_shutdown()
Date: Mon, 14 Sep 2026 08:24:48 +0000 [thread overview]
Message-ID: <20260914082449.334741F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260914081149.1916589-3-itai.handler@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Returning early from `spi_nor_shutdown()` when `spi_nor_prep_and_lock()` is interrupted by a signal skips critical hardware restoration, potentially bricking the device on next boot.
Pre-existing issues:
- [High] Missing `spi_nor_unprep()` on the error path of `spi_nor_prep_and_lock()` and its variants causes controller resource leaks and potential deadlocks.
--
commit 45363f008a63391ea1e85be5cb9b77e5c2d59277
Author: Itai Handler <itai.handler@gmail.com>
mtd: spi-nor: take the flash lock in spi_nor_shutdown()
This commit acquires the flash lock in spi_nor_shutdown() to serialize
device restoration with concurrent operations. This prevents the restore
command from being ignored by a busy flash chip or corrupting an ongoing
read operation during system shutdown.
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 8bc117b46e028..647bf8dce7193 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -3862,8 +3862,21 @@ static int spi_nor_remove(struct spi_mem *spimem)
> static void spi_nor_shutdown(struct spi_mem *spimem)
> {
> struct spi_nor *nor = spi_mem_get_drvdata(spimem);
> + int ret;
> +
> + /*
> + * Wait for an operation started by another thread to finish.
> + * device_shutdown() runs with MTD users still active: a busy flash
> + * ignores the commands spi_nor_restore() issues, leaving it in
> + * 4-byte address mode, and a restore landing mid-read changes the
> + * chip's address width under the transfer.
> + */
> + ret = spi_nor_prep_and_lock(nor);
> + if (ret)
> + return;
[Severity: High]
If wait_event_killable() in spi_nor_prep_and_lock() is interrupted by a fatal
signal, it returns -ERESTARTSYS. Will returning early here skip the critical
hardware restoration in spi_nor_restore()?
If the flash chip is left in 4-byte addressing mode, could the bootloader
read garbage data on the next boot, effectively soft-bricking the device
until a hard power cycle?
[Severity: High]
This isn't a bug introduced by this patch, but does spi_nor_prep_and_lock()
leak controller resources on its error path?
Looking at spi_nor_prep_and_lock() in drivers/mtd/spi-nor/core.c:
int spi_nor_prep_and_lock(struct spi_nor *nor)
{
int ret;
ret = spi_nor_prep(nor);
if (ret)
return ret;
if (!spi_nor_use_parallel_locking(nor))
mutex_lock(&nor->lock);
else
ret = wait_event_killable(nor->rww.wait,
spi_nor_rww_start_exclusive(nor));
return ret;
}
If wait_event_killable() is interrupted and returns an error, the function
returns without calling spi_nor_unprep(nor). Could this permanently leak the
hardware locks and clocks enabled in spi_nor_prep(), deadlocking the
controller for all subsequent SPI operations?
The same behavior appears to be present in the spi_nor_prep_and_lock_pe() and
spi_nor_prep_and_lock_rd() variants.
>
> spi_nor_restore(nor);
> + spi_nor_unlock_and_unprep(nor);
> }
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260914081149.1916589-1-itai.handler@gmail.com?part=2
next prev parent reply other threads:[~2026-09-14 8:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 8:11 [PATCH v2 0/3] mtd: spi-nor: fix the unlocked restore on shutdown and remove Itai Handler
2026-09-14 8:11 ` [PATCH v2 1/3] mtd: spi-nor: fix the lock left held by spi_nor_rww_start_exclusive() Itai Handler
2026-09-14 8:22 ` sashiko-bot
2026-09-14 12:09 ` Miquel Raynal
2026-09-14 12:20 ` Michael Walle
2026-09-14 12:34 ` Miquel Raynal
2026-09-14 12:41 ` Michael Walle
2026-09-14 13:11 ` Miquel Raynal
2026-09-14 8:11 ` [PATCH v2 2/3] mtd: spi-nor: take the flash lock in spi_nor_shutdown() Itai Handler
2026-09-14 8:24 ` sashiko-bot [this message]
2026-09-14 12:15 ` Miquel Raynal
2026-09-14 8:11 ` [PATCH v2 3/3] mtd: spi-nor: take the flash lock in spi_nor_remove() Itai Handler
2026-09-14 8:26 ` sashiko-bot
2026-09-14 12:19 ` Miquel Raynal
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=20260914082449.334741F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=itai.handler@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=mwalle@kernel.org \
--cc=pratyush@kernel.org \
--cc=richard@nod.at \
--cc=sashiko-reviews@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=takahiro.kuwano@infineon.com \
--cc=vigneshr@ti.com \
/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
all inboxes | Powered by JetHome®