[PATCH v2] mtd: spinand: micron: add support for MT29F1G01AAADD
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Fri Nov 27 15:57:00 PST 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mtd: spinand: micron: divide-by-zero in
micron_4_ooblayout_ecc() and _free()
--
commit 44ca4db24b5a7a324981c1c01700cebe8a1210b0
Author: Vít Kazík <vitkazik at vitkazik.cz>
mtd: spinand: micron: add support for MT29F1G01AAADD
This commit adds support and an OOB layout for the Micron MT29F1G01AAADD
(M68A) 1Gb 3.3V SPI NAND flash chip.
> diff --git a/drivers/mtd/nand/spi/micron.c b/drivers/mtd/nand/spi/micron.c
> index 36f6cbbd7462c..34a8ea77c3fe9 100644
> --- a/drivers/mtd/nand/spi/micron.c
> +++ b/drivers/mtd/nand/spi/micron.c
> @@ -134,6 +134,24 @@ static const struct mtd_ooblayout_ops micron_4_ooblayout = {
> .free = micron_4_ooblayout_free,
> };
>
> +static int micron_m68a_ooblayout_free(struct mtd_info *mtd, int section,
> + struct mtd_oob_region *region)
> +{
> + if (section >= 4)
> + return -ERANGE;
> +
> + /* 2 bytes for the BBM + 2 bytes of non-ECC protected memory */
> + region->offset = (section * 16) + 4;
> + region->length = 4;
> +
> + return 0;
> +}
> +
> +static const struct mtd_ooblayout_ops micron_m68a_ooblayout = {
> + .ecc = micron_4_ooblayout_ecc,
> + .free = micron_m68a_ooblayout_free,
> +};
[Severity: Medium]
Can micron_4_ooblayout_ecc() divide by zero when MT29F1G01AAADD is probed
without an ECC engine (e.g. nand-no-ecc-engine in Device Tree)?
micron_4_ooblayout_ecc() bounds section by dividing by mtd->ecc_step_size:
drivers/mtd/nand/spi/micron.c:micron_4_ooblayout_ecc() {
...
if (section >= spinand->base.memorg.pagesize /
mtd->ecc_step_size)
return -ERANGE;
...
}
In spinand_init(), when nand->ecc.engine is NULL, spinand->eccinfo.ooblayout
is still installed on mtd while nanddev_get_ecc_conf(nand)->step_size is 0,
leaving mtd->ecc_step_size as 0. During device registration in
spinand_probe(), mtd_device_register() -> add_mtd_device() ->
mtd_debugfs_populate() calls mtd_ooblayout_ecc(mtd, 0, ®ion), hitting
a divide-by-zero in micron_4_ooblayout_ecc().
(Note that micron_4_ooblayout_free() has the same division by
mtd->ecc_step_size, which already divides by zero during spinand_init()
because mtd_ooblayout_count_freebytes() runs before mtd->ecc_step_size is
populated.)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127234301.262679-1-vitkazik@vitkazik.cz?part=1
More information about the linux-mtd
mailing list