* [PATCH] mtd: spinand: set request type explicitly in spinand_{is,mark}bad() functions
@ 2026-11-17 16:20 Gabor Juhos
2026-11-17 16:27 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Gabor Juhos @ 2026-11-17 16:20 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Boris Brezillon
Cc: linux-mtd, linux-kernel, Sashiko, Gabor Juhos
Commit 701981cab016 ("mtd: nand: Add a NAND page I/O request type")
added a 'type' member to the 'nand_page_io_req' structure and updated
the request iterators to utilize that, but the spinand_{is,mark}bad()
functions were not updated by the commit. However in both of these
functions the new member is implicitly inititalized to zero which
corresponds to NAND_PAGE_READ. This is correct for the spinand_isbad()
function since that uses a read request to get the bad block marker
bytes, but the spinand_markbad() function does a write request so it
should set the request type to NAND_PAGE_WRITE.
Change the spinand_markbad() function to set the request type to the
correct NAND_PAGE_WRITE value. For consistency, also update the
spinand_isbad() function to set the request type to NAND_PAGE_READ
explicitly.
Fixes: 701981cab016 ("mtd: nand: Add a NAND page I/O request type")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/log/192383 # See "**Investigating `req->type` in NAND Write Operations**"
Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
---
drivers/mtd/nand/spi/core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 18bba02fbd31..35bcb4a8861b 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -1105,6 +1105,7 @@ static bool spinand_isbad(struct nand_device *nand, const struct nand_pos *pos)
struct spinand_device *spinand = nand_to_spinand(nand);
u8 marker[2] = { };
struct nand_page_io_req req = {
+ .type = NAND_PAGE_READ,
.pos = *pos,
.ooblen = sizeof(marker),
.ooboffs = 0,
@@ -1148,6 +1149,7 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos)
struct spinand_device *spinand = nand_to_spinand(nand);
u8 marker[2] = { };
struct nand_page_io_req req = {
+ .type = NAND_PAGE_WRITE,
.pos = *pos,
.ooboffs = 0,
.ooblen = sizeof(marker),
---
base-commit: 760d2efe91a84363d25c1051a10572242e75fe86
change-id: 20261117-spinand-set-req-type-in-bbm-functions-34775e6c14e0
Best regards,
--
Gabor Juhos <j4g8y7@gmail.com>
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd: spinand: set request type explicitly in spinand_{is,mark}bad() functions
2026-11-17 16:20 [PATCH] mtd: spinand: set request type explicitly in spinand_{is,mark}bad() functions Gabor Juhos
@ 2026-11-17 16:27 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-17 16:27 UTC (permalink / raw)
To: Gabor Juhos, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, Boris Brezillon
Cc: linux-mtd
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] mtd: spinand: 1-byte bad block marker overlap in
ooblayout_free() [1]
--
commit cd3136a28caa4c65d360f664085cbb1e630acb0f
Author: Gabor Juhos <j4g8y7@gmail.com>
mtd: spinand: set request type explicitly in spinand_{is,mark}bad() functions
This commit explicitly sets req.type to NAND_PAGE_READ in spinand_isbad()
and NAND_PAGE_WRITE in spinand_markbad().
Link: https://sashiko.dev/#/log/192383
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index 18bba02fbd31f..35bcb4a8861b4 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -1105,6 +1105,7 @@ static bool spinand_isbad(struct nand_device *nand, const struct nand_pos *pos)
> struct spinand_device *spinand = nand_to_spinand(nand);
> u8 marker[2] = { };
> struct nand_page_io_req req = {
> + .type = NAND_PAGE_READ,
> .pos = *pos,
> .ooblen = sizeof(marker),
> .ooboffs = 0,
[Severity: Critical]
This problem wasn't introduced by this patch, but can the 2-byte marker[]
read in spinand_isbad() [1] collide with free OOB space on chips that
reserve only 1 byte for the bad block marker?
spinand_isbad() treats a block as bad whenever marker[0] != 0xff ||
marker[1] != 0xff, reading OOB offsets 0 and 1. However, several vendor
ooblayout_free() callbacks expose OOB offset 1 as free space:
drivers/mtd/nand/spi/gigadevice.c:gd5fxgq4xa_ooblayout_free() {
...
} else {
/* section 0 has one byte reserved for bad block mark */
region->offset = 1;
region->length = 7;
}
}
When an upper layer writes OOB data into that free region, it overwrites
OOB offset 1, causing later spinand_isbad() checks to falsely report good
blocks as bad.
[1] https://sashiko.dev/#/bug/linux-6f85551a-da14-43d9-91eb-800d68b3b9c4
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-spinand-set-req-type-in-bbm-functions-v1-1-f46d5b3b8cf3@gmail.com?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-17 16:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 16:20 [PATCH] mtd: spinand: set request type explicitly in spinand_{is,mark}bad() functions Gabor Juhos
2026-11-17 16:27 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox