[PATCH v4 2/3] mtd: rawnand: Add Cortina CS7542 controller support
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Thu Nov 26 05:05:11 PST 2026
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] mtd: rawnand: cs752x: broken child lookup when nand at 0 is
disabled
- [Medium] mtd: rawnand: cs752x: broken page writes with
NAND_ECC_ENGINE_TYPE_NONE
--
commit 27b8a6ca04060af07bea917b577d9528c58349c2
Author: Fil Dunsky <filipp.dunsky at 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 at 0 is disabled and nand at 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 at 0 has status = "disabled" and nand at 1 is enabled, probe
fails instead of finding nand at 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
More information about the linux-mtd
mailing list