[PATCH v2] spi: spi-qpic-snand: reject when no enough OOB space

From: Ziyang Huang

Date: Mon Aug 17 2026 - 11:49:45 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>
---
Changes since v1:
Remove the mistaken lint.

drivers/spi/spi-qpic-snand.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/spi/spi-qpic-snand.c b/drivers/spi/spi-qpic-snand.c
index b6c58d9cfe14..624550bff40a 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);

/*
--
2.40.1