Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fil Dunsky" <filipp.dunsky@gmail.com>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Philipp Zabel" <p.zabel@pengutronix.de>
Cc: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 2/3] mtd: rawnand: Add Cortina CS7542 controller support
Date: Thu, 26 Nov 2026 13:05:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-235556@kernel.org> (raw)
In-Reply-To: <20261126-b4-cs7542-nand-v4-2-38e488f6f8b1@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mtd: rawnand: cs752x: broken child lookup when nand@0 is
  disabled
- [Medium] mtd: rawnand: cs752x: broken page writes with
  NAND_ECC_ENGINE_TYPE_NONE
--

commit 27b8a6ca04060af07bea917b577d9528c58349c2
Author: Fil Dunsky <filipp.dunsky@gmail.com>

mtd: rawnand: Add Cortina CS7542 controller support

This commit adds a raw NAND flash controller driver for the Cortina Systems
CS7542 SoC using programmed I/O, supporting software ECC and hardware Hamming
ECC.

> diff --git a/drivers/mtd/nand/raw/cs752x_nand.c b/drivers/mtd/nand/raw/cs752x_nand.c
> new file mode 100644
> index 0000000000000..b4cc24e31faee
> --- /dev/null
> +++ b/drivers/mtd/nand/raw/cs752x_nand.c
[ ... ]
> +static int cs752x_nand_exec_op(struct nand_chip *chip,
> +			       const struct nand_operation *op, bool check_only)
> +{
[ ... ]
> +	if (p.data && p.data->type == NAND_OP_DATA_OUT_INSTR)
> +		return cs752x_nand_pio(h, &p, (u8 *)p.data->ctx.data.buf.out,
> +				      requested, true);
> +
> +	ret = cs752x_nand_pio(h, &p, h->own_buf, len,
> +			      p.command == NAND_CMD_RESET);
> +	if (ret)
> +		return ret;
[ ... ]
> +static int cs752x_nand_attach_chip(struct nand_chip *chip)
> +{
> +	struct mtd_info *mtd = nand_to_mtd(chip);
> +	struct cs752x_nand_host *h = to_host(chip);
> +	int ecc_total;
> +
> +	/* Byte-bus transfer handling and the staging buffer are driver limits. */
> +	if (chip->options & NAND_BUSWIDTH_16 ||
> +	    mtd->writesize + mtd->oobsize > sizeof(h->own_buf) ||
> +	    mtd->writesize % sizeof(u32) || mtd->oobsize % sizeof(u32))
> +		return -EOPNOTSUPP;
> +	chip->ecc.read_page_raw = nand_monolithic_read_page_raw;
> +	chip->ecc.write_page_raw = nand_monolithic_write_page_raw;
> +	if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_SOFT ||
> +	    chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_NONE)
> +		return 0;

[Severity: Medium]
Do page writes work when NAND_ECC_ENGINE_TYPE_NONE is selected?

nand_scan_tail() runs after attach_chip() and unconditionally overwrites
chip->ecc.read_page, write_page, read_page_raw, and write_page_raw in the
NAND_ECC_ENGINE_TYPE_NONE case:

drivers/mtd/nand/raw/nand_base.c:nand_scan_tail() {
    ...
	case NAND_ECC_ENGINE_TYPE_NONE:
		pr_warn("NAND_ECC_ENGINE_TYPE_NONE selected by board driver. This is not recommended!\n");
		ecc->read_page = nand_read_page_raw;
		ecc->write_page = nand_write_page_raw;
		ecc->read_oob = nand_read_oob_std;
		ecc->read_page_raw = nand_read_page_raw;
		ecc->write_page_raw = nand_write_page_raw;
    ...
}

Unlike nand_monolithic_write_page_raw(), nand_write_page_raw() splits a page
program across nand_prog_page_begin_op(), nand_write_data_op(), and
nand_prog_page_end_op().  cs752x_nand_pio() pulses ECC_RESET_NF_RESET at the
end of nand_prog_page_begin_op(), resetting the controller before the confirm
command is sent, and cs752x_nand_exec_op() then issues the standalone
NAND_CMD_PAGEPROG confirm command with write = false (FLASH_RD instead of
FLASH_WT).

[ ... ]

> +static int cs752x_nand_probe(struct platform_device *pdev)
> +{
[ ... ]
> +	if (of_get_available_child_count(dev->of_node) != 1)
> +		return dev_err_probe(dev, -EOPNOTSUPP,
> +				     "one connected NAND target is supported\n");
> +	flash = of_get_available_child_by_name(dev->of_node, "nand");
> +
> +	if (!flash)
> +		return dev_err_probe(dev, -ENODEV, "missing NAND chip node\n");

[Severity: Medium]
Does of_get_available_child_by_name(dev->of_node, "nand") fail with -ENODEV
when nand@0 is disabled and nand@1 is enabled?

of_get_available_child_by_name() calls of_get_child_by_name(), which returns
the first child matching "nand" regardless of its status, and then returns
NULL immediately if that child is not available:

drivers/of/base.c:of_get_available_child_by_name() {
    ...
	child = of_get_child_by_name(node, name);
	if (child && !of_device_is_available(child)) {
		of_node_put(child);
		return NULL;
	}
    ...
}

On a board where nand@0 has status = "disabled" and nand@1 is enabled, probe
fails instead of finding nand@1.  Using of_get_next_available_child() (and
checking of_node_name_eq(flash, "nand")) would locate the enabled child on
either chip select.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-b4-cs7542-nand-v4-0-38e488f6f8b1@gmail.com?part=2

  reply	other threads:[~2026-11-26 13:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 12:45 [PATCH v4 0/3] Add Cortina Systems CS7542 NAND controller support Fil Dunsky via B4 Relay
2026-11-26 12:45 ` [PATCH v4 1/3] dt-bindings: mtd: Add Cortina CS7542 NAND controller Fil Dunsky via B4 Relay
2026-11-26 12:45 ` [PATCH v4 2/3] mtd: rawnand: Add Cortina CS7542 controller support Fil Dunsky via B4 Relay
2026-11-26 13:05   ` sashiko-bot [this message]
2026-11-26 12:45 ` [PATCH v4 3/3] MAINTAINERS: Add Cortina CS7542 NAND controller entry Fil Dunsky via B4 Relay

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=sashiko-outbox-235556@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=filipp.dunsky@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=p.zabel@pengutronix.de \
    --cc=richard@nod.at \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox