All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>
Cc: "Michael Walle" <mwalle@kernel.org>,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Takahiro Kuwano" <takahiro.kuwano@infineon.com>,
	linux-sunxi@lists.linux.dev,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Pratyush Yadav" <pratyush@kernel.org>
Subject: Re: [PATCH v2] mtd: rawnand: sunxi: fit maximized ECC step to page size
Date: Fri, 04 Sep 2026 22:47:28 +0000	[thread overview]
Message-ID: <20260904224728.A2A781F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260904-submit-sunxi-nand-ecc-step-validation-v2-1-6e3ba6200948@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] ECC strength maximization overestimates available capacity for 512-byte pages due to a bit-length calculation mismatch, causing initialization failures.
--

commit de85ead656c2f999d69dec7e2c0a592634ba071e
Author: James Hilliard <james.hilliard1@gmail.com>

mtd: rawnand: sunxi: fit maximized ECC step to page size

This commit addresses an issue where maximizing ECC strength for a NAND
with a 512-byte page yields zero ECC steps. It modifies the driver to
dynamically select a 512-byte step for 512-byte pages, while retaining
1024-byte steps for larger pages.

> diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c
> index 83666dd6cb2a8..de1e6b49f79aa 100644
> --- a/drivers/mtd/nand/raw/sunxi_nand.c
> +++ b/drivers/mtd/nand/raw/sunxi_nand.c
> @@ -2084,7 +2084,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
>  	if (nanddev->ecc.user_conf.flags & NAND_ECC_MAXIMIZE_STRENGTH) {
>  		int bytes = mtd->oobsize;
>  
> -		ecc->size = 1024;
> +		ecc->size = min_t(unsigned int, mtd->writesize, 1024);

[Severity: High]
Does setting ecc->size to 512 for 512-byte pages cause a bit-length
calculation mismatch downstream?

When ecc->size is 512, the maximum ECC strength is estimated using 13 bits
per symbol (fls(4096)):

sunxi_nand_hw_ecc_ctrl_init() {
    ...
		ecc->strength = bytes * 8 / fls(8 * ecc->size);
    ...
}

However, the driver later unconditionally calculates the required ECC bytes
assuming 14 bits per symbol:

sunxi_nand_hw_ecc_ctrl_init() {
    ...
	/* HW ECC always request ECC bytes for 1024 bytes blocks */
	ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * 1024), 8);
    ...
}

This mismatch overestimates the maximum strength. For example, with 26
available OOB bytes, the 13-bit estimation incorrectly selects a strength of
16, but the 14-bit calculation requires 28 bytes. 

The subsequent bounds check:

sunxi_nand_hw_ecc_ctrl_init() {
    ...
	if (mtd->oobsize < (ecc->bytes * nsectors + total_user_data_sz))
		return -EINVAL;
    ...
}

then fails, causing the driver probe to abort for 512-byte page devices when
nand-ecc-maximize is enabled.

>  		nsectors = mtd->writesize / ecc->size;
>  
>  		if (!nfc->caps->reg_user_data_len) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260904-submit-sunxi-nand-ecc-step-validation-v2-1-6e3ba6200948@gmail.com?part=1

  reply	other threads:[~2026-09-04 22:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04 22:39 [PATCH v2] mtd: rawnand: sunxi: fit maximized ECC step to page size James Hilliard
2026-09-04 22:39 ` James Hilliard
2026-09-04 22:47 ` sashiko-bot [this message]
2026-09-08 10:03 ` Miquel Raynal
2026-09-08 10:03   ` Miquel Raynal
2026-09-08 15:27   ` James Hilliard
2026-09-08 15:27     ` James Hilliard
2026-09-08 15:55     ` Miquel Raynal

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=20260904224728.A2A781F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=james.hilliard1@gmail.com \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=miquel.raynal@bootlin.com \
    --cc=mwalle@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=takahiro.kuwano@infineon.com \
    --cc=vigneshr@ti.com \
    /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.