From: Miquel Raynal <miquel.raynal@bootlin.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: linux-mtd@lists.infradead.org, linux-sunxi@lists.linux.dev,
stable@vger.kernel.org, Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Richard Genoud <richard.genoud@bootlin.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Boris Brezillon <bbrezillon@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: rawnand: sunxi: reject invalid ECC step sizes
Date: Fri, 04 Sep 2026 17:25:28 +0200 [thread overview]
Message-ID: <87ecf911jr.fsf@bootlin.com> (raw)
In-Reply-To: <20260811060651.227431-1-james.hilliard1@gmail.com> (James Hilliard's message of "Tue, 11 Aug 2026 00:06:48 -0600")
On 11/08/2026 at 00:06:48 -06, James Hilliard <james.hilliard1@gmail.com> wrote:
> ECC maximization forces a 1024-byte ECC step and divides the
> available OOB bytes by the number of steps. A NAND with a smaller
> page therefore produces zero steps and a division by zero.
No, steps cannot be < 1. If they are, it's a bug that must be fixed.
> An explicitly configured ECC step which is larger than, or does not
> divide, the page also produces an unusable step count before the NAND
> core can diagnose the configuration.
>
> Validate the step size at both points where the driver derives the
> number of sectors and reject invalid geometries.
>
> Fixes: 4796d8655915 ("mtd: nand: sunxi: Support ECC maximization")
> Cc: stable@vger.kernel.org
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
> drivers/mtd/nand/raw/sunxi_nand.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c
> index 45ccbce91551..ad314c0e30b2 100644
> --- a/drivers/mtd/nand/raw/sunxi_nand.c
> +++ b/drivers/mtd/nand/raw/sunxi_nand.c
> @@ -2032,6 +2032,15 @@ static void sunxi_nand_detach_chip(struct nand_chip *nand)
> sunxi_nand->user_data_bytes = NULL;
> }
>
> +static int sunxi_nfc_ecc_steps(struct mtd_info *mtd, unsigned int step_size)
> +{
> + if (!step_size || mtd->writesize < step_size ||
> + mtd->writesize % step_size)
I don't get it, mtd->writesize < step_size is conceptually
impossible. If that happens, it must be fixed earlier than that.
> + return -EINVAL;
> +
> + return mtd->writesize / step_size;
> +}
> +
> static int sunxi_nfc_maximize_user_data(struct nand_chip *nand, uint32_t oobsize,
> int ecc_bytes, int nsectors)
> {
Thanks,
Miquèl
WARNING: multiple messages have this Message-ID (diff)
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: linux-mtd@lists.infradead.org, linux-sunxi@lists.linux.dev,
stable@vger.kernel.org, Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Richard Genoud <richard.genoud@bootlin.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Boris Brezillon <bbrezillon@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: rawnand: sunxi: reject invalid ECC step sizes
Date: Fri, 04 Sep 2026 17:25:28 +0200 [thread overview]
Message-ID: <87ecf911jr.fsf@bootlin.com> (raw)
In-Reply-To: <20260811060651.227431-1-james.hilliard1@gmail.com> (James Hilliard's message of "Tue, 11 Aug 2026 00:06:48 -0600")
On 11/08/2026 at 00:06:48 -06, James Hilliard <james.hilliard1@gmail.com> wrote:
> ECC maximization forces a 1024-byte ECC step and divides the
> available OOB bytes by the number of steps. A NAND with a smaller
> page therefore produces zero steps and a division by zero.
No, steps cannot be < 1. If they are, it's a bug that must be fixed.
> An explicitly configured ECC step which is larger than, or does not
> divide, the page also produces an unusable step count before the NAND
> core can diagnose the configuration.
>
> Validate the step size at both points where the driver derives the
> number of sectors and reject invalid geometries.
>
> Fixes: 4796d8655915 ("mtd: nand: sunxi: Support ECC maximization")
> Cc: stable@vger.kernel.org
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
> drivers/mtd/nand/raw/sunxi_nand.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c
> index 45ccbce91551..ad314c0e30b2 100644
> --- a/drivers/mtd/nand/raw/sunxi_nand.c
> +++ b/drivers/mtd/nand/raw/sunxi_nand.c
> @@ -2032,6 +2032,15 @@ static void sunxi_nand_detach_chip(struct nand_chip *nand)
> sunxi_nand->user_data_bytes = NULL;
> }
>
> +static int sunxi_nfc_ecc_steps(struct mtd_info *mtd, unsigned int step_size)
> +{
> + if (!step_size || mtd->writesize < step_size ||
> + mtd->writesize % step_size)
I don't get it, mtd->writesize < step_size is conceptually
impossible. If that happens, it must be fixed earlier than that.
> + return -EINVAL;
> +
> + return mtd->writesize / step_size;
> +}
> +
> static int sunxi_nfc_maximize_user_data(struct nand_chip *nand, uint32_t oobsize,
> int ecc_bytes, int nsectors)
> {
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-09-04 15:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 6:06 [PATCH] mtd: rawnand: sunxi: reject invalid ECC step sizes James Hilliard
2026-08-11 6:06 ` James Hilliard
2026-09-04 15:25 ` Miquel Raynal [this message]
2026-09-04 15:25 ` Miquel Raynal
2026-09-04 16:52 ` James Hilliard
2026-09-04 16:52 ` James Hilliard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ecf911jr.fsf@bootlin.com \
--to=miquel.raynal@bootlin.com \
--cc=bbrezillon@kernel.org \
--cc=geert+renesas@glider.be \
--cc=james.hilliard1@gmail.com \
--cc=jernej.skrabec@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=richard.genoud@bootlin.com \
--cc=richard@nod.at \
--cc=samuel@sholland.org \
--cc=stable@vger.kernel.org \
--cc=vigneshr@ti.com \
--cc=wens@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.