Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Arseniy Krasnov" <AVKrasnov@sberdevices.ru>,
	"Boris Brezillon" <bbrezillon@kernel.org>,
	"Kyle Roeschley" <kyle.roeschley@ni.com>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH 1/2] mtd: rawnand: macronix: serialize OTP access with NAND operations
Date: Sun, 08 Nov 2026 21:32:32 +0000	[thread overview]
Message-ID: <sashiko-outbox-204080@kernel.org> (raw)
In-Reply-To: <20261108-submit-rawnand-operation-locking-v1-v1-1-565010fc5f8b@gmail.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Medium] mtd: rawnand: macronix: clobbered error return in
  __macronix_30lfxg18ac_rw_otp() [1]
--

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

mtd: rawnand: macronix: serialize OTP access with NAND operations

This commit exposes nand_get_device() and nand_release_device() within the
raw NAND core and uses them to serialize Macronix OTP transactions with
normal NAND operations and suspend handling.

> diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c
> index 03237310852cb..4fe7036ae9921 100644
> --- a/drivers/mtd/nand/raw/nand_macronix.c
> +++ b/drivers/mtd/nand/raw/nand_macronix.c
> @@ -380,6 +380,7 @@ static int __macronix_30lfxg18ac_rw_otp(struct mtd_info *mtd,
>  	int ret;
>  
>  	nand = mtd_to_nand(mtd);
> +	nand_get_device(nand);
>  	nand_select_target(nand, 0);
>  
>  	ret = macronix_30lfxg18ac_otp_enable(nand);
> @@ -426,6 +427,7 @@ static int __macronix_30lfxg18ac_rw_otp(struct mtd_info *mtd,
>  			write ? "write" : "read");
>  
>  	nand_deselect_target(nand);
> +	nand_release_device(nand);
>  
>  	return ret;
>  }

[Severity: Medium]
This problem wasn't introduced by this patch, but doesn't the out_otp
cleanup path clobber ret [1] with the result of
macronix_30lfxg18ac_otp_disable()?

drivers/mtd/nand/raw/nand_macronix.c:__macronix_30lfxg18ac_rw_otp() {
	...
	ret = macronix_30lfxg18ac_otp_enable(nand);
	if (ret)
		goto out_otp;
	...
out_otp:
	if (ret)
		dev_err(&mtd->dev, "failed to perform OTP IO: %i\n", ret);

	ret = macronix_30lfxg18ac_otp_disable(nand);
	if (ret)
		dev_err(&mtd->dev, "failed to leave OTP mode after %s\n",
			write ? "write" : "read");

	nand_deselect_target(nand);
	nand_release_device(nand);

	return ret;
}

When macronix_30lfxg18ac_otp_enable(), nand_prog_page_op(), or
nand_read_page_op() fails and macronix_30lfxg18ac_otp_disable() then
succeeds, __macronix_30lfxg18ac_rw_otp() returns 0 without updating
*retlen, causing callers such as mtd_read_user_prot_reg() to treat OTP I/O
errors as 0-byte transfers.  Jumping to out_otp when
macronix_30lfxg18ac_otp_enable() fails also calls
macronix_30lfxg18ac_otp_disable() even though OTP mode was never enabled.

[1] https://sashiko.dev/#/bug/linux-c639ea49-b980-45c7-9d77-b0e264970125

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261108-submit-rawnand-operation-locking-v1-v1-0-565010fc5f8b@gmail.com?part=1

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2026-11-08 21:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-08 21:23 [PATCH 0/2] mtd: rawnand: serialize OTP and BBT recovery operations James Hilliard
2026-11-08 21:23 ` [PATCH 1/2] mtd: rawnand: macronix: serialize OTP access with NAND operations James Hilliard
2026-11-08 21:32   ` sashiko-bot [this message]
2026-11-08 21:23 ` [PATCH 2/2] mtd: rawnand: serialize bad-block marker writes during BBT recovery 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=sashiko-outbox-204080@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=AVKrasnov@sberdevices.ru \
    --cc=bbrezillon@kernel.org \
    --cc=james.hilliard1@gmail.com \
    --cc=kyle.roeschley@ni.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --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