mtd: spi-nor: take the flash lock around spi_nor_restore()
Subsystems (3)
PATCH v5 1/1 mtd: spi-nor: take the flash lock around spi_nor_restore()
spi_nor_restore() runs on reboot, kexec and unbind to hand the flash over in its power-on state. It runs without nor->lock while the MTD device is still registered. Tasks are not frozen on reboot or kexec, and kexec -e does not even stop user space, so the restore can run in the middle of a program or erase. This causes two problems:
1. The flash can be left in the wrong state. On boards that do not reset the flash (broken-flash-reset), the restore exits 4-byte address mode, but a busy flash typically ignores the command, so the flash stays in 4-byte mode after the reboot or kexec. After a reboot, a boot ROM that reads the flash in the power-on 3-byte mode gets the wrong data, and the board fails to boot. For example, the GnuBee PC1 (MT7621) has a Winbond W25Q256FV, which ignores the exit command while busy, and the board needs the restore to reboot, see commit 90dedc973b86 ("staging: mt7621-dts: allow gnubee to reboot cleanly."). A busy flash also ignores READ ID, so if it is still busy when the secondary kernel probes it after a kexec, the probe fails ("unrecognized JEDEC id bytes"), and that kernel cannot use the flash.
2. Data can be corrupted. The restore also soft resets flashes that support it, which can abort a program or erase. For example, the Micron MT25QU512ABB8ESF-0SIT QSPI NOR flash advertises the soft reset in its SFDP, and its data sheet says that a reset aborts a program or erase in progress and may corrupt data. If an application is writing data to the device when the system kexecs into a secondary kernel, or restarts, a sector can be left partly erased or programmed.
Take the lock, so that the restore waits for the operation in flight. That alone is not enough: the next operation would then start right after the restore, and could still be running at the kexec or be cut short by the reboot. And after an exit from 4-byte mode, it would still use 4-byte addresses, so a page program would write to the wrong place. So mark the flash shut down before releasing the lock, and fail later operations with -ESHUTDOWN. The CFI drivers also refuse operations once they have reset the flash for a reboot (see cfi_intelext_reset()). If the SPI controller removes itself on shutdown, spi_nor_remove() runs after spi_nor_shutdown(), finds the flash shut down, and does not restore it a second time.
The wait is usually short, as applications and flash file systems typically submit small requests, such as a single sector erase. It can be long, though: spi_nor_erase() holds the lock for the whole request, so shutdown or unbind may wait for a full chip erase, which can take minutes. If the lock cannot be taken, warn and restore without it, as before.
Backport note: before v6.4, the lock helper is spi_nor_lock_and_prep(), and it has no _pe and _rd variants. From v6.4 on, apply this on top of commit f594a33f9721 ("mtd: spi-nor: Unprepare legacy controllers upon RWW wait interruption"), which is also tagged for stable.
---
Changes in v5:
- Fail operations after the restore with -ESHUTDOWN, so that none can reach the flash between the restore and the reboot or kexec.
- Warn and restore anyway when the lock cannot be taken, instead of skipping the restore, as I offered in my reply on v3 [1].
- Use a helper around spi_nor_restore() again, as in v3, and the v3 subject.
- Say that the wait can last for a full chip erase; v4 understated it.
- Drop the long code comment, and rewrite the commit message, with examples and a backport note.
- Use the v3 form of Assisted-by.
- Rebase on mainline.
Why the lock is not just kept after the restore, which would also stop later operations: it hangs the reboot or kexec on boards whose SPI controller removes itself on shutdown (spi-fsl-dspi, spi-bcm2835, spi-ath79). spi_nor_remove() then runs after spi_nor_shutdown(), in the same task, and waits for the lock that spi_nor_shutdown() kept. With this patch, spi_nor_remove() gets the lock and skips the restore.
Testing:
- Built with W=1 for arm64, on mainline and, cherry-picked on top of f594a33f9721, on 6.6, 6.12, 6.18, 7.2 and 7.3. The backports to 5.10, 5.15 and 6.1 build cleanly too; I will send them when the stable team asks.
- In QEMU (v7.3, ZynqMP GQSPI, n25q512a11 with broken-flash-reset, and the flash model patched to stay busy during an erase), with an application erasing and programming the flash during a kexec:
- Without this patch, the flash ignores WREN, EX4B and WRDI, and stays in 4-byte mode.
- With a draft that released the lock after the restore, the next erase went out with a 4-byte address. With a 10 s erase, it was still running when the secondary kernel probed the flash, and the probe failed.
- With this patch, the flash obeys EX4B, nothing reaches it after the restore, and the secondary kernel finds the flash, with both a 3 s and a 10 s erase.
- With the GQSPI driver changed to remove itself on shutdown, as spi-fsl-dspi does, a kexec with a draft that kept the lock hung, as spi_nor_remove() waited for it. With this patch, it completes, and the flash is restored once.
v4: https://lore.kernel.org/r/[email protected]
v3: https://lore.kernel.org/r/[email protected]
[1] https://lore.kernel.org/r/CAFpOueRGN2TSNo+m3319qn00p-BYn8w7OQ6OPt4XTcVG63-uUA@mail.gmail.com
drivers/mtd/spi-nor/core.c | 43 +++++++++++++++++++++++++++++++++++-- include/linux/mtd/spi-nor.h | 2 ++ 2 files changed, 43 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/core.c +41 -2
@@ -1230,6 +1230,11 @@ int spi_nor_prep_and_lock(struct spi_nor *nor) ret =wait_event_killable (nor->rww.wait,spi_nor_rww_start_exclusive (nor)); +if (!ret && nor->shutdown) { +spi_nor_unlock_and_unprep (nor); +return -ESHUTDOWN ; + } +if (ret)spi_nor_unprep (nor);
@@ -1290,6 +1295,8 @@ static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len) rww->ongoing_pe = false; } +static void spi_nor_unlock_and_unprep_pe (struct spi_nor *nor,loff_t start,size_t len); +static int spi_nor_prep_and_lock_pe (struct spi_nor *nor,loff_t start,size_t len) {int ret;
@@ -1304,6 +1311,11 @@ static int spi_nor_prep_and_lock_pe(struct spi_nor *nor, loff_t start, size_t le ret =wait_event_killable (nor->rww.wait,spi_nor_rww_start_pe (nor, start, len)); +if (!ret && nor->shutdown) { +spi_nor_unlock_and_unprep_pe (nor, start, len); +return -ESHUTDOWN ; + } +if (ret)spi_nor_unprep (nor);
@@ -1366,6 +1378,8 @@ static void spi_nor_rww_end_rd(struct spi_nor *nor, loff_t start, size_t len) rww->ongoing_rd = false; } +static void spi_nor_unlock_and_unprep_rd (struct spi_nor *nor,loff_t start,size_t len); +static int spi_nor_prep_and_lock_rd (struct spi_nor *nor,loff_t start,size_t len) {int ret;
@@ -1380,6 +1394,11 @@ static int spi_nor_prep_and_lock_rd(struct spi_nor *nor, loff_t start, size_t le ret =wait_event_killable (nor->rww.wait,spi_nor_rww_start_rd (nor, start, len)); +if (!ret && nor->shutdown) { +spi_nor_unlock_and_unprep_rd (nor, start, len); +return -ESHUTDOWN ; + } +if (ret)spi_nor_unprep (nor);
@@ -3250,6 +3269,26 @@ static void spi_nor_restore(struct spi_nor *nor)spi_nor_soft_reset (nor); } +static void spi_nor_lock_and_restore (struct spi_nor *nor) +{ +int ret; + + ret =spi_nor_prep_and_lock (nor); +if (ret == -ESHUTDOWN ) +return ; +if (ret) +dev_warn (nor->dev, +"Failed to lock flash, restoring its power-on state anyway, err = %d\n" , + ret); + +spi_nor_restore (nor); + +if (!ret) { + nor->shutdown = true; +spi_nor_unlock_and_unprep (nor); + } +} +static const struct flash_info *spi_nor_match_name (struct spi_nor *nor,const char *name) {
@@ -3632,7 +3671,7 @@ static int spi_nor_remove(struct spi_mem *spimem) {struct spi_nor *nor =spi_mem_get_drvdata (spimem); -spi_nor_restore (nor); +spi_nor_lock_and_restore (nor);/* Clean up MTD stuff. */ return mtd_device_unregister (&nor->mtd);
@@ -3642,7 +3681,7 @@ static void spi_nor_shutdown(struct spi_mem *spimem) {struct spi_nor *nor =spi_mem_get_drvdata (spimem); -spi_nor_restore (nor); +spi_nor_lock_and_restore (nor); }/*
include/linux/mtd/spi-nor.h +2 -0
@@ -361,6 +361,7 @@ struct spi_nor_flash_parameter;* @read_opcode: the read opcode * @read_dummy: the dummy needed by the read operation * @program_opcode: the program opcode +* @shutdown: the flash was restored, refuse further operations * @sst_write_second: used by the SST write operation * @read_proto: the SPI protocol for read operations * @write_proto: the SPI protocol for write operations
@@ -402,6 +403,7 @@ struct spi_nor {enum spi_nor_protocol read_proto;enum spi_nor_protocol write_proto;enum spi_nor_protocol reg_proto; +bool shutdown;bool sst_write_second;struct sfdp *sfdp;struct dentry *debugfs_root;
base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
Signature · 1 line
2.34.1
Hi Michael, Pratyush,
Gentle ping on this fix. It still applies cleanly on top of v7.4-rc2 and spi-nor/next.
Could you please take a look when you have a moment? I'm happy to rework it if anything needs changing.
Thanks,
Itai
Michael Walle
maintainerQuoted 112 lines · Itai Handler
spi_nor_restore()runs on reboot, kexec and unbind to hand the flash over in its power-on state. It runs withoutnor->lockwhile the MTD device is still registered. Tasks are not frozen on reboot or kexec, and kexec -e does not even stop user space, so the restore can run in the middle of a program or erase. This causes two problems:1. The flash can be left in the wrong state. On boards that do not reset the flash (broken-flash-reset), the restore exits 4-byte address mode, but a busy flash typically ignores the command, so the flash stays in 4-byte mode after the reboot or kexec. After a reboot, a boot ROM that reads the flash in the power-on 3-byte mode gets the wrong data, and the board fails to boot. For example, the GnuBee PC1 (MT7621) has a Winbond W25Q256FV, which ignores the exit command while busy, and the board needs the restore to reboot, see commit
90dedc973b86("staging: mt7621-dts: allow gnubee to reboot cleanly."). A busy flash also ignores READ ID, so if it is still busy when the secondary kernel probes it after a kexec, the probe fails ("unrecognized JEDEC id bytes"), and that kernel cannot use the flash.2. Data can be corrupted. The restore also soft resets flashes that support it, which can abort a program or erase. For example, the Micron MT25QU512ABB8ESF-0SIT QSPI NOR flash advertises the soft reset in its SFDP, and its data sheet says that a reset aborts a program or erase in progress and may corrupt data. If an application is writing data to the device when the system kexecs into a secondary kernel, or restarts, a sector can be left partly erased or programmed.
Take the lock, so that the restore waits for the operation in flight. That alone is not enough: the next operation would then start right after the restore, and could still be running at the kexec or be cut short by the reboot. And after an exit from 4-byte mode, it would still use 4-byte addresses, so a page program would write to the wrong place. So mark the flash shut down before releasing the lock, and fail later operations with
-ESHUTDOWN. The CFI drivers also refuse operations once they have reset the flash for a reboot (seecfi_intelext_reset()). If the SPI controller removes itself on shutdown,spi_nor_remove()runs afterspi_nor_shutdown(), finds the flash shut down, and does not restore it a second time.The wait is usually short, as applications and flash file systems typically submit small requests, such as a single sector erase. It can be long, though:
spi_nor_erase()holds the lock for the whole request, so shutdown or unbind may wait for a full chip erase, which can take minutes. If the lock cannot be taken, warn and restore without it, as before.Backport note: before v6.4, the lock helper is
spi_nor_lock_and_prep(), and it has no_peand_rdvariants. From v6.4 on, apply this on top of commitf594a33f9721("mtd: spi-nor: Unprepare legacy controllers upon RWW wait interruption"), which is also tagged for stable.Fixes 59b356ffd0b0 ("mtd: m25p80: restore the status of SPI flash when exiting")Cc [email protected] # see patch description, needs adjustments for <= 6.3Assisted-by LLMSigned-off-by Itai Handler <[email protected]>---
Changes in v5:
- Fail operations after the restore with-ESHUTDOWN, so that none can reach the flash between the restore and the reboot or kexec.
- Warn and restore anyway when the lock cannot be taken, instead of skipping the restore, as I offered in my reply on v3 [1].
- Use a helper aroundspi_nor_restore()again, as in v3, and the v3 subject.
- Say that the wait can last for a full chip erase; v4 understated it.
- Drop the long code comment, and rewrite the commit message, with examples and a backport note.
- Use the v3 form of Assisted-by.
- Rebase on mainline.Why the lock is not just kept after the restore, which would also stop later operations: it hangs the reboot or kexec on boards whose SPI controller removes itself on shutdown (spi-fsl-dspi, spi-bcm2835, spi-ath79).
spi_nor_remove()then runs afterspi_nor_shutdown(), in the same task, and waits for the lock thatspi_nor_shutdown()kept. With this patch,spi_nor_remove()gets the lock and skips the restore.Testing:
- Built with W=1 for arm64, on mainline and, cherry-picked on top off594a33f9721, on 6.6, 6.12, 6.18, 7.2 and 7.3. The backports to 5.10, 5.15 and 6.1 build cleanly too; I will send them when the stable team asks.
- In QEMU (v7.3, ZynqMP GQSPI, n25q512a11 with broken-flash-reset, and the flash model patched to stay busy during an erase), with an application erasing and programming the flash during a kexec:
- Without this patch, the flash ignores WREN, EX4B and WRDI, and stays in 4-byte mode.
- With a draft that released the lock after the restore, the next erase went out with a 4-byte address. With a 10 s erase, it was still running when the secondary kernel probed the flash, and the probe failed.
- With this patch, the flash obeys EX4B, nothing reaches it after the restore, and the secondary kernel finds the flash, with both a 3 s and a 10 s erase.
- With the GQSPI driver changed to remove itself on shutdown, as spi-fsl-dspi does, a kexec with a draft that kept the lock hung, asspi_nor_remove()waited for it. With this patch, it completes, and the flash is restored once.v4: https://lore.kernel.org/r/[email protected]
v3: https://lore.kernel.org/r/[email protected]
[1] https://lore.kernel.org/r/CAFpOueRGN2TSNo+m3319qn00p-BYn8w7OQ6OPt4XTcVG63-uUA@mail.gmail.comdrivers/mtd/spi-nor/core.c | 43 +++++++++++++++++++++++++++++++++++-- include/linux/mtd/spi-nor.h | 2 ++ 2 files changed, 43 insertions(+), 2 deletions(-)drivers/mtd/spi-nor/core.c +0
-0
drivers/mtd/spi-nor/core.c int spi_nor_prep_and_lock(struct spi_nor *nor) · line 1235
Quoted 6 lines
drivers/mtd/spi-nor/core.c +3
-0@@ -1230,6 +1230,11 @@ int spi_nor_prep_and_lock(struct spi_nor *nor) ret =wait_event_killable (nor->rww.wait,spi_nor_rww_start_exclusive (nor)); +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?
drivers/mtd/spi-nor/core.c static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len) · line 1299
Quoted 11 lines
drivers/mtd/spi-nor/core.c +4
-0+ } +if (ret)spi_nor_unprep (nor);@@ -1290,6 +1295,8 @@ static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len) rww->ongoing_pe = false; } +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.
Quoted 37 lines
drivers/mtd/spi-nor/core.c +12
-0static int spi_nor_prep_and_lock_pe (struct spi_nor *nor,loff_t start,size_t len) {int ret;@@ -1304,6 +1311,11 @@ static int spi_nor_prep_and_lock_pe(struct spi_nor *nor, loff_t start, size_t le ret =wait_event_killable (nor->rww.wait,spi_nor_rww_start_pe (nor, start, len)); +if (!ret && nor->shutdown) { +spi_nor_unlock_and_unprep_pe (nor, start, len); +return -ESHUTDOWN ; + } +if (ret)spi_nor_unprep (nor);@@ -1366,6 +1378,8 @@ static void spi_nor_rww_end_rd(struct spi_nor *nor, loff_t start, size_t len) rww->ongoing_rd = false; } +static void spi_nor_unlock_and_unprep_rd (struct spi_nor *nor,loff_t start,size_t len); +static int spi_nor_prep_and_lock_rd (struct spi_nor *nor,loff_t start,size_t len) {int ret;@@ -1380,6 +1394,11 @@ static int spi_nor_prep_and_lock_rd(struct spi_nor *nor, loff_t start, size_t le ret =wait_event_killable (nor->rww.wait,spi_nor_rww_start_rd (nor, start, len)); +if (!ret && nor->shutdown) { +spi_nor_unlock_and_unprep_rd (nor, start, len); +return -ESHUTDOWN ; + } +if (ret)spi_nor_unprep (nor);
drivers/mtd/spi-nor/core.c static void spi_nor_restore(struct spi_nor *nor) · line 3277
Quoted 9 lines
drivers/mtd/spi-nor/core.c +6
-0@@ -3250,6 +3269,26 @@ static void spi_nor_restore(struct spi_nor *nor)spi_nor_soft_reset (nor); } +static void spi_nor_lock_and_restore (struct spi_nor *nor) +{ +int ret; + + 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
drivers/mtd/spi-nor/core.c static void spi_nor_restore(struct spi_nor *nor) · line 3287
Quoted 10 lines
drivers/mtd/spi-nor/core.c +10
-0+return ; +if (ret) +dev_warn (nor->dev, +"Failed to lock flash, restoring its power-on state anyway, err = %d\n" , + ret); + +spi_nor_restore (nor); + +if (!ret) { + nor->shutdown = true;
Why don't you set the flag unconditionally?
drivers/mtd/spi-nor/core.c static int spi_nor_remove(struct spi_mem *spimem) · line 3674
Quoted 13 lines
drivers/mtd/spi-nor/core.c +5
-1+spi_nor_unlock_and_unprep (nor); + } +} +static const struct flash_info *spi_nor_match_name (struct spi_nor *nor,const char *name) {@@ -3632,7 +3671,7 @@ static int spi_nor_remove(struct spi_mem *spimem) {struct spi_nor *nor =spi_mem_get_drvdata (spimem); -spi_nor_restore (nor); +spi_nor_lock_and_restore (nor);
So why don't you just keep spi_nor_restore() and just add the locking there?
What about the following:
static void spi_nor_restore(struct spi_nor *nor)
{
struct spi_nor_flash_parameter *params = nor->params;
int lock_ret, ret;
lock_ret = spi_nor_prep_and_lock(nor);
/* already restored, e.g. remove() after shutdown(). */
if (nor->restored)
return;
if (lock_ret)
dev_warn(nor->dev, "...", lock_ret);
/* former body .. */
/* refuse any further operations */
nor->restored = true;
if (!lock_ret) {
spi_nor_unlock_and_unprep(nor);
}
}Quoted 17 lines
drivers/mtd/spi-nor/core.c +1
-1/* Clean up MTD stuff. */ return mtd_device_unregister (&nor->mtd);@@ -3642,7 +3681,7 @@ static void spi_nor_shutdown(struct spi_mem *spimem) {struct spi_nor *nor =spi_mem_get_drvdata (spimem); -spi_nor_restore (nor); +spi_nor_lock_and_restore (nor); }/* include/linux/mtd/spi-nor.h +0
-0
include/linux/mtd/spi-nor.h struct spi_nor_flash_parameter; · line 364
Quoted 4 lines
include/linux/mtd/spi-nor.h +1
-0@@ -361,6 +361,7 @@ struct spi_nor_flash_parameter;* @read_opcode: the read opcode * @read_dummy: the dummy needed by the read operation * @program_opcode: the program opcode +* @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'?
-michael
Quoted 13 lines
include/linux/mtd/spi-nor.h +1
-0* @sst_write_second: used by the SST write operation * @read_proto: the SPI protocol for read operations * @write_proto: the SPI protocol for write operations @@ -402,6 +403,7 @@ struct spi_nor {enum spi_nor_protocol read_proto;enum spi_nor_protocol write_proto;enum spi_nor_protocol reg_proto; +bool shutdown;bool sst_write_second;struct sfdp *sfdp;struct dentry *debugfs_root;base-commit:
c339f4010dea8b0d754f84ace70cd1b089878ef8
Miquel Raynal
maintainerQuoted 9 lines
drivers/mtd/spi-nor/core.c static void spi_nor_restore(struct spi_nor *nor) · line 3277
Quoted 7 lines
drivers/mtd/spi-nor/core.c +6
-0+static void spi_nor_lock_and_restore (struct spi_nor *nor) +{ +int ret; + + ret =spi_nor_prep_and_lock (nor); +if (ret == -ESHUTDOWN )This is actually really hard to follow.
Yes, I tried to review this patch and eventually stopped. Please teach your AI to not overengineer its solutions.
Thanks,
Miquèl
Quoted 6 lines · Michael Walle
drivers/mtd/spi-nor/core.c int spi_nor_prep_and_lock(struct spi_nor *nor) · line 1235
Quoted 3 lines
drivers/mtd/spi-nor/core.c +3
-0+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.
Quoted 4 lines
drivers/mtd/spi-nor/core.c static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len) · line 1299
Quoted 2 lines
drivers/mtd/spi-nor/core.c +2
-0+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.
Quoted 6 lines
drivers/mtd/spi-nor/core.c static void spi_nor_restore(struct spi_nor *nor) · line 3277
Quoted 2 lines
drivers/mtd/spi-nor/core.c +2
-0+ 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.
Quoted 4 lines
drivers/mtd/spi-nor/core.c static void spi_nor_restore(struct spi_nor *nor) · line 3287
Quoted 2 lines
drivers/mtd/spi-nor/core.c +2
-0+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.
Quoted 4 lines
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.
Quoted 4 lines
Quoted 1 line
+ * @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
Quoted 7 lines · Miquel Raynal
Quoted 4 lines
drivers/mtd/spi-nor/core.c static void spi_nor_restore(struct spi_nor *nor) · line 3277
Quoted 2 lines
drivers/mtd/spi-nor/core.c +2
-0+ ret =spi_nor_prep_and_lock (nor); +if (ret == -ESHUTDOWN )This is actually really hard to follow.
Yes, I tried to review this patch and eventually stopped. Please teach your AI to not overengineer its solutions.
Sorry for the time it cost you. That one is on me: I sent it, and I should have made it simpler before sending it.
v6 is simpler. It follows Michael's sketch: spi_nor_restore() takes the lock itself and then sets a "restored" flag, and the lock helpers fail any later operation with -EIO. The extra helper and the special error code are gone, and the commit message is about half as long. The diff is longer than v5's only because the _pe and _rd unlock helpers move up, as Michael asked.
Thanks,
Itai