From: Itai Handler <itai.handler@gmail.com>
To: mwalle@kernel.org
Cc: miquel.raynal@bootlin.com, pratyush@kernel.org, richard@nod.at,
vigneshr@ti.com, takahiro.kuwano@infineon.com,
tudor.ambarus@linaro.org, linux-mtd@lists.infradead.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v5] mtd: spi-nor: take the flash lock around spi_nor_restore()
Date: Wed, 18 Nov 2026 19:12:35 +0200 [thread overview]
Message-ID: <20261118171235.3886698-1-itai.handler@gmail.com> (raw)
In-Reply-To: <DMYDITU0H48Z.2LA5KF2TFNUY2@kernel.org>
On Wed Nov 18, 2026 at 2:33 PM CET, Michael Walle wrote:
>> + if (!ret && nor->shutdown) {
>> + spi_nor_unlock_and_unprep(nor);
>> + return -ESHUTDOWN;
>
> This will be propagated to userspace, correct? Not sure this is a
> valid error code outside of sockets. Maybe EIO?
Yes, it reaches user space, e.g. through the MTD char device. v6
returns -EIO, which is also what the CFI drivers return once they have
reset the flash for a reboot.
>> +static void spi_nor_unlock_and_unprep_pe(struct spi_nor *nor, loff_t start, size_t len);
>> +
>
> Please avoid forward declarations and move the functions.
Done.
>> + ret = spi_nor_prep_and_lock(nor);
>> + if (ret == -ESHUTDOWN)
>
> This is actually really hard to follow. It's tested for even before
> it is set down below. Also probably wont work with an EIO return
> code. See more below
Agreed. v6 tests the flag instead.
>> + if (!ret) {
>> + nor->shutdown = true;
>
> Why don't you set the flag unconditionally?
No good reason. v6 sets it unconditionally. When the lock could not be
taken, another operation can then read the flag at the same time, so
v6 uses WRITE_ONCE() and READ_ONCE() for it.
> So why don't you just keep spi_nor_restore() and just add the
> locking there?
>
> What about the following:
v6 does that, as in your sketch, except that it tests the flag before
taking the lock. Your order works too, since spi_nor_prep_and_lock()
fails for a restored flash and releases the lock again, but testing
first does not rely on that. Only spi_nor_restore() sets the flag, and
it runs from ->shutdown() and ->remove(), which the driver core
serializes with the device lock, so that test needs no lock.
One more change in v6: spi_nor_remove() restored the flash before
mtd_device_unregister(), so with the flag, the unregister could no
longer write back data, e.g. mtdblock's cache. v6 unregisters first.
>> + * @shutdown: the flash was restored, refuse further operations
>
> shutdown only covers some of its meaning, it might also just get
> unbinded etc. So what about 'restored'?
Renamed to "restored".
v6 is out now.
Thanks,
Itai
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
prev parent reply other threads:[~2026-11-18 17:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 21:01 [PATCH v5] mtd: spi-nor: take the flash lock around spi_nor_restore() Itai Handler
2026-11-10 8:27 ` Itai Handler
2026-11-18 13:33 ` Michael Walle
2026-11-18 14:23 ` Miquel Raynal
2026-11-18 17:13 ` Itai Handler
2026-11-18 17:12 ` Itai Handler [this message]
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=20261118171235.3886698-1-itai.handler@gmail.com \
--to=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=stable@vger.kernel.org \
--cc=takahiro.kuwano@infineon.com \
--cc=tudor.ambarus@linaro.org \
--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