| From 6873788fbf8ab0ab8ed66779da40c02d508f818d Mon Sep 17 00:00:00 2001 | |
| From: Sasha Levin <sashal@kernel.org> | |
| Date: Tue, 6 Oct 2026 13:56:05 -0400 | |
| Subject: mtd: spinand: fix NULL pointer dereference with no ECC engine | |
| MIME-Version: 1.0 | |
| Content-Type: text/plain; charset=UTF-8 | |
| Content-Transfer-Encoding: 8bit | |
| From: Nuno Sá <nuno.sa@analog.com> | |
| [ Upstream commit b890e6163761ddb580cc74f43e15f8bbde15647e ] | |
| When "nand-no-ecc-engine" is set in DT, nanddev_get_ecc_engine() takes | |
| the NAND_ECC_ENGINE_TYPE_NONE path and returns success while leaving | |
| nand->ecc.engine NULL. The SPI-NAND code nevertheless dereferences it | |
| unconditionally to test for a pipelined engine, so probing such a | |
| device oopses immediately. | |
| Rather than open-coding the test three times, add a | |
| nand_ecc_is_pipelined() helper to the NAND core that folds the NULL | |
| check into the integration comparison, and use it everywhere. Future | |
| callers then cannot reintroduce the problem. | |
| Fixes: f9d7c7265bcf ("mtd: spinand: Create direct mapping descriptors for ECC operations") | |
| Cc: stable@vger.kernel.org | |
| Signed-off-by: Nuno Sá <nuno.sa@analog.com> | |
| Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> | |
| [ sashal: replaced the new nand_ecc_is_pipelined() helper with an inline NULL check in spinand_create_dirmap() ] | |
| Signed-off-by: Sasha Levin <sashal@kernel.org> | |
| --- | |
| drivers/mtd/nand/spi/core.c | 3 ++- | |
| 1 file changed, 2 insertions(+), 1 deletion(-) | |
| diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c | |
| index 04965f21c995f..9143553bc5704 100644 | |
| --- a/drivers/mtd/nand/spi/core.c | |
| +++ b/drivers/mtd/nand/spi/core.c | |
| @@ -884,7 +884,8 @@ static int spinand_create_dirmap(struct spinand_device *spinand, | |
| spinand->dirmaps[plane].rdesc = desc; | |
| - if (nand->ecc.engine->integration != NAND_ECC_ENGINE_INTEGRATION_PIPELINED) { | |
| + if (!nand->ecc.engine || | |
| + nand->ecc.engine->integration != NAND_ECC_ENGINE_INTEGRATION_PIPELINED) { | |
| spinand->dirmaps[plane].wdesc_ecc = spinand->dirmaps[plane].wdesc; | |
| spinand->dirmaps[plane].rdesc_ecc = spinand->dirmaps[plane].rdesc; | |
| -- | |
| 2.53.0 | |