ARM Sunxi Platform Development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	linux-sunxi@lists.linux.dev
Subject: Re: [PATCH v3 13/15] mtd: rawnand: sunxi: avoid duplicate chip setup before page commands
Date: Wed, 09 Sep 2026 08:54:34 +0000	[thread overview]
Message-ID: <20260909085434.C8F201F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260909-submit-sunxi-nand-vendor-oob-layout-v1-v3-13-838cb0ba1547@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Wait queue spinlock corruption and false completion due to concurrent complete() and init_completion() after a timeout.
--

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

mtd: rawnand: sunxi: avoid duplicate chip setup before page commands

The page helpers invoke exec_op(), which selects the chip and programs
its timing and spare-area registers. Remove the identical setup directly
before those helpers in the read callbacks and PIO write callbacks.

> diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c
> index dc5b3814657e7..0d829103b144b 100644
> --- a/drivers/mtd/nand/raw/sunxi_nand.c
> +++ b/drivers/mtd/nand/raw/sunxi_nand.c
> @@ -1743,8 +1743,6 @@ static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, uint8_t *buf,
>  	int ret, i, cur_off = 0;
>  	bool erased_chunk_found = false;
>  
> -	sunxi_nfc_select_chip(nand, nand->cur_cs);
> -
>  	ret = nand_read_page_op(nand, page, 0, NULL, 0);
>  	if (ret)
>  		return ret;

[ ... ]

While reviewing this code, I noticed a separate issue in sunxi_nfc_wait_events():

drivers/mtd/nand/raw/sunxi_nand.c:sunxi_nfc_wait_events() {
    ...
	if (!use_polling) {
		init_completion(&nfc->complete);
    ...
}

[Severity: High]
This isn't a bug introduced by this patch, but is a pre-existing issue. Can
this lead to wait queue spinlock corruption and false completions?

If a NAND operation times out in sunxi_nfc_wait_events(), CPU A clears the
interrupt enable register and returns -ETIMEDOUT.

Concurrently, if the IRQ handler is delayed, CPU B executing
sunxi_nfc_interrupt() may read the active status before CPU A clears it, but
get preempted before calling complete().

CPU A then starts a new NAND operation and re-enters sunxi_nfc_wait_events():

drivers/mtd/nand/raw/sunxi_nand.c:sunxi_nfc_wait_events() {
    ...
	if (!use_polling) {
		init_completion(&nfc->complete);
    ...
}

When CPU B resumes and calls complete(), wouldn't it access and modify the
lock concurrently, causing lock corruption?

Furthermore, wouldn't it set the completion flag for the new command, causing
it to return prematurely and process garbage data?

Since there is no structural prevention like synchronize_irq() or
disable_irq() on the timeout path, does this need to be addressed?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909-submit-sunxi-nand-vendor-oob-layout-v1-v3-0-838cb0ba1547@gmail.com?part=13

  reply	other threads:[~2026-09-09  8:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  8:30 [PATCH v3 00/15] mtd: rawnand: sunxi: support the Allwinner randomized OOB format James Hilliard
2026-09-09  8:30 ` [PATCH v3 01/15] mtd: rawnand: sunxi: use the logical step's OOB length in PIO James Hilliard
2026-09-09  8:30 ` [PATCH v3 02/15] mtd: rawnand: sunxi: propagate page-setup and erased-check errors James Hilliard
2026-09-09  8:30 ` [PATCH v3 03/15] mtd: rawnand: sunxi: stop failed program operations and disable ECC James Hilliard
2026-09-09  8:30 ` [PATCH v3 04/15] mtd: rawnand: sunxi: select the pattern ID for the current ECC step James Hilliard
2026-09-09  8:30 ` [PATCH v3 05/15] mtd: rawnand: sunxi: propagate buffer and column transfer errors James Hilliard
2026-09-09  8:30 ` [PATCH v3 06/15] mtd: rawnand: sunxi: avoid a second program confirm for OOB writes James Hilliard
2026-09-09  8:30 ` [PATCH v3 07/15] mtd: rawnand: sunxi: avoid redundant column changes for extra OOB James Hilliard
2026-09-09  8:30 ` [PATCH v3 08/15] mtd: rawnand: sunxi: clarify OOB register and step handling James Hilliard
2026-09-09  8:30 ` [PATCH v3 09/15] dt-bindings: mtd: sunxi: Add randomized OOB flag James Hilliard
2026-09-09  8:30 ` [PATCH v3 10/15] mtd: rawnand: sunxi: support randomized OOB formats James Hilliard
2026-09-09  8:44   ` sashiko-bot
2026-09-09  8:30 ` [PATCH v3 11/15] mtd: rawnand: sunxi: select the packed H6/H616 OOB layout James Hilliard
2026-09-09  8:51   ` sashiko-bot
2026-09-09  8:30 ` [PATCH v3 12/15] mtd: rawnand: sunxi: combine contiguous unprotected OOB reads James Hilliard
2026-09-09  8:30 ` [PATCH v3 13/15] mtd: rawnand: sunxi: avoid duplicate chip setup before page commands James Hilliard
2026-09-09  8:54   ` sashiko-bot [this message]
2026-09-09  8:30 ` [PATCH v3 14/15] mtd: rawnand: sunxi: reduce user-data length register accesses James Hilliard
2026-09-09  8:30 ` [PATCH v3 15/15] mtd: rawnand: sunxi: reuse ECC status within each DMA read 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=20260909085434.C8F201F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=james.hilliard1@gmail.com \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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