[PATCH] spi: spi-qpic-snand: reject when no enough OOB space
From: Ziyang Huang
Date: Sun Aug 16 2026 - 09:45:29 EST
Print a clear error when the flash doesn't have enough space, instand of
return -EBADMSG silently in read or write functions.
ECC4 requires 64B OOB space.
ECC8 requires 80B OOB space.
Signed-off-by: Ziyang Huang <hzyitc@xxxxxxxxxxx>
---
drivers/spi/spi-qpic-snand.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index b6c58d9cfe14..3d0013e5687f 100644
--- a/drivers/spi/spi-qpic-snand.c
+++ b/drivers/spi/spi-qpic-snand.c
@@ -323,6 +323,15 @@ static int qcom_spi_ecc_init_ctx_pipelined(struct nand_device *nand)
ecc_cfg->cw_size = ecc_cfg->cw_data + ecc_cfg->bytes;
bad_block_byte = mtd->writesize - ecc_cfg->cw_size * (cwperpage - 1) + 1;
+ if ((ecc_cfg->cw_size * cwperpage) > (mtd->writesize + mtd->oobsize)) {
+ dev_err(snandc->dev,
+ "Current ECC settings require %d bytes, but the flash only has %d+%d bytes.\n",
+ (ecc_cfg->cw_size * cwperpage), mtd->writesize,
+ mtd->oobsize);
+ ret = -EINVAL;
+ goto err_free_ecc_cfg;
+ }
+
mtd_set_ooblayout(mtd, &qcom_spi_ooblayout);
/*
@@ -1659,4 +1668,3 @@ module_platform_driver(qcom_spi_driver);
MODULE_DESCRIPTION("SPI driver for QPIC QSPI cores");
MODULE_AUTHOR("Md Sadre Alam <quic_mdalam@xxxxxxxxxxx>");
MODULE_LICENSE("GPL");
-
--
2.40.1