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 v6 2/3] mtd: rawnand: Add Cortina CS7542 controller support
Date: Tue, 01 Dec 2026 06:15:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-242685@kernel.org> (raw)
In-Reply-To: <20261201-b4-cs7542-nand-v6-2-e6b0d712745b@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mtd: rawnand: cs752x: PIO deadline overwritten by WAITRDY
  timeout
--

commit 95d3ff6afab1a14e1b8da8939e0a268251a75175
Author: Fil Dunsky <filipp.dunsky@gmail.com>

mtd: rawnand: Add Cortina CS7542 controller support

This commit adds a raw NAND controller driver for the Cortina Systems
CS7542 SoC using programmed I/O, 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..dfd6cbae7bc78
> --- /dev/null
> +++ b/drivers/mtd/nand/raw/cs752x_nand.c

[ ... ]

> +static int cs752x_nand_words(struct cs752x_nand_host *h, u8 *buf,
> +			     unsigned int len, bool write)
> +{
> +	u32 value;
> +	unsigned int i;
> +	int ret;
> +
> +	if (len % sizeof(u32))
> +		return -EINVAL;
> +	for (i = 0; i < len; i += sizeof(u32)) {
> +		if (write)
> +			fl_writel(h, FLASH_NF_DATA, get_unaligned_le32(buf + i));
> +		fl_writel(h, FLASH_FLASH_ACCESS_START,
> +			  FLASH_START_REGREQ | FLASH_START_CMD(write ? FLASH_WT : FLASH_RD));
> +		ret = readl_poll_timeout_atomic(h->iobase_fl + FLASH_FLASH_ACCESS_START,
> +						value, !(value & FLASH_START_REGREQ), 1, 10000);

[ ... ]

> +static int cs752x_nand_supports_op(const struct nand_operation *op,
> +				   struct cs752x_nand_op *p)
> +{
> +	unsigned int i, state = 0;
> +
> +	memset(p, 0, sizeof(*p));
> +	p->timeout_ms = 100;
> +	if (op->cs || !op->ninstrs || op->ninstrs > 8)
> +		return -EOPNOTSUPP;
> +	for (i = 0; i < op->ninstrs; i++) {
> +		const struct nand_op_instr *in = &op->instrs[i];
> +		unsigned int j;
> +
> +		p->delay_ns = max(p->delay_ns, in->delay_ns);
> +		switch (in->type) {

[ ... ]

> +		case NAND_OP_WAITRDY_INSTR:
> +			if (p->wait_ready || !in->ctx.waitrdy.timeout_ms ||
> +			    state == 3 || state == 4)
> +				return -EOPNOTSUPP;
> +			p->wait_ready = true;
> +			p->timeout_ms = in->ctx.waitrdy.timeout_ms;
> +			break;
> +		default:
> +			return -EOPNOTSUPP;
> +		}
> +	}

[ ... ]

> +static int cs752x_nand_pio(struct cs752x_nand_host *h,
> +			   const struct cs752x_nand_op *p, u8 *buf,
> +			   unsigned int len, bool write)
> +{

[ ... ]

> +	/* The PIO transfer has one budget, independent of the NAND R/B wait. */
> +	deadline = ktime_get_ns() + p->timeout_ms * (u64)NSEC_PER_MSEC;
> +	for (i = 0; i < max(len, 1U); i += step) {
> +		u64 now = ktime_get_ns();
> +
> +		if (now >= deadline) {
> +			ret = -ETIMEDOUT;
> +			goto out;
> +		}
> +		if (write && len)
> +			fl_writel(h, FLASH_NF_DATA, get_unaligned_le32(buf + i));
> +		fl_writel(h, FLASH_FLASH_ACCESS_START,
> +			  FLASH_START_REGREQ | FLASH_START_CMD(write ? FLASH_WT : FLASH_RD));
> +		/* Byte PIO completes in microseconds, below scheduler granularity. */
> +		ret = readl_poll_timeout_atomic(h->iobase_fl + FLASH_FLASH_ACCESS_START,
> +						value, !(value & FLASH_START_REGREQ), 1,
> +					DIV_ROUND_UP_ULL(deadline - now, NSEC_PER_USEC));

[Severity: High]
Does overwriting p->timeout_ms with in->ctx.waitrdy.timeout_ms clobber the
100 ms PIO transfer deadline in cs752x_nand_pio()?

Standard NAND read operations such as nand_read_param_page_op() and
nand_lp_exec_read_page_op() pass NAND_COMMON_TIMING_MS(conf, tR_max) as
the WAITRDY timeout, which is 1 ms in SDR mode 0 (tR_max = 200 us).
cs752x_nand_pio() then uses that 1 ms p->timeout_ms as the wall-clock
deadline for the entire byte-PIO loop (up to 4,608 single-byte iterations
for NAND_CMD_PARAM or 4,224 iterations for a 4KiB page read).

Because readl_poll_timeout_atomic() is called with delay_us = 1 on every
byte (and on every 32-bit word in cs752x_nand_words()), each poll iteration
that sees FLASH_START_REGREQ still set executes udelay(1), adding 2.1 to
4.6 ms of busy-wait across a single page or parameter read and causing
cs752x_nand_pio() to fail with -ETIMEDOUT before the transfer finishes
(or whenever the preemptible caller is delayed by 1 ms).

Keeping the WAITRDY timeout in a separate field from the PIO transfer
budget and passing 0 for delay_us in readl_poll_timeout_atomic() would
avoid both the premature timeout and the per-byte udelay(1) overhead.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-b4-cs7542-nand-v6-0-e6b0d712745b@gmail.com?part=2

  reply	other threads:[~2026-12-01  6:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  5:58 [PATCH v6 0/3] Add Cortina Systems CS7542 NAND controller support Fil Dunsky via B4 Relay
2026-12-01  5:58 ` [PATCH v6 1/3] dt-bindings: mtd: Add Cortina CS7542 NAND controller Fil Dunsky via B4 Relay
2026-12-01  5:58 ` [PATCH v6 2/3] mtd: rawnand: Add Cortina CS7542 controller support Fil Dunsky via B4 Relay
2026-12-01  6:15   ` sashiko-bot [this message]
2026-12-01  5:58 ` [PATCH v6 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-242685@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