Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Srikanth Boyapally" <srikanth.boyapally@amd.com>,
	"Pratyush Yadav" <pratyush@kernel.org>,
	"Michael Walle" <mwalle@kernel.org>,
	"Takahiro Kuwano" <takahiro.kuwano@infineon.com>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Vignesh Raghavendra" <vigneshr@ti.com>
Cc: linux-mtd@lists.infradead.org, michal.simek@amd.com, git@amd.com,
	"Sai Krishna Potthuri" <sai.krishna.potthuri@amd.com>
Subject: Re: [PATCH 2/2] mtd: spi-nor: Reset flash device on resume
Date: Fri, 20 Nov 2026 11:19:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-225022@kernel.org> (raw)
In-Reply-To: <20261120-nor_11_20-v1-2-70332a54037f@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] mtd: spi-nor: address mode desync after spi_nor_hw_reset() in
  spi_nor_resume()
- [Low] mtd: spi-nor: devm_gpiod_get_optional() called on every resume
  without reset GPIO
--

commit 8bc5dd906a0cb0351d12cf228c9c04ee639a4d57
Author: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>

mtd: spi-nor: Reset flash device on resume

This commit calls spi_nor_hw_reset() in spi_nor_resume() to reset the
flash device before reinitializing it with spi_nor_init().

> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 11227f8fa8ea9..29bce6b7348d0 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c

[ ... ]

> @@ -3191,6 +3194,10 @@ static void spi_nor_resume(struct mtd_info *mtd)
>  	struct device *dev = nor->dev;
>  	int ret;
>  
> +	ret = spi_nor_hw_reset(nor);
> +	if (ret)
> +		dev_err(dev, "device reset failed during resume()\n");
> +
>  	/* re-initialize the nor chip */
>  	ret = spi_nor_init(nor);
>  	if (ret)

[Severity: High]
Does spi_nor_hw_reset() desynchronize nor->params->addr_mode_nbytes from
the flash's hardware address mode on resume?

When 4-byte address mode is enabled during probe,
spi_nor_set_4byte_addr_mode() sets nor->params->addr_mode_nbytes = 4.
Pulsing the reset GPIO in spi_nor_resume() resets the flash hardware back
to its power-on default 3-byte address mode while leaving
addr_mode_nbytes at 4.

spi_nor_init() then runs spi_nor_set_octal_dtr() and spi_nor_quad_enable()
before spi_nor_set_4byte_addr_mode():

drivers/mtd/spi-nor/core.c:spi_nor_init() {
	err = spi_nor_set_octal_dtr(nor, true);
	...
	err = spi_nor_quad_enable(nor);
	...
	if (nor->addr_nbytes == 4 &&
	    nor->read_proto != SNOR_PROTO_8_8_8_DTR &&
	    !(params->flags & SNOR_F_4B_OPCODES))
		return spi_nor_set_4byte_addr_mode(nor, true);
}

Callbacks such as micron_st_nor_octal_dtr_en(), cypress_nor_octal_dtr_en()
and cypress_nor_quad_enable_volatile_reg() use addr_mode_nbytes to send
Read/Write Any Register commands, so they will send 4 address bytes to a
chip expecting 3 and fail to re-enable octal DTR or quad mode.

In addition, multi-die Micron/ST flashes enable 4-byte address mode in
their late_init hooks (such as micron_st_nor_two_die_late_init()) even
when SNOR_F_4B_OPCODES is set or read_proto is SNOR_PROTO_8_8_8_DTR,
because SPINOR_OP_MT_DIE_ERASE has no 4-byte opcode.  Because
spi_nor_init() skips spi_nor_set_4byte_addr_mode() for those flashes,
they remain stuck in 3-byte address mode after resume, breaking die erase.

[Severity: Low]
When a flash does not have an optional reset GPIO, nor->reset remains
NULL after probe.  Does calling spi_nor_hw_reset() from spi_nor_resume()
cause devm_gpiod_get_optional() to be re-invoked on every resume cycle?

drivers/mtd/spi-nor/core.c:spi_nor_hw_reset() {
	struct gpio_desc *reset = nor->reset;

	if (!reset) {
		reset = devm_gpiod_get_optional(nor->dev, "reset", GPIOD_OUT_LOW);
		if (IS_ERR_OR_NULL(reset))
			return PTR_ERR_OR_ZERO(reset);
		nor->reset = reset;
	}
...
}

Acquiring the devm-managed GPIO during probe and only toggling nor->reset
in spi_nor_hw_reset() when it is non-NULL would avoid repeated devm
lookups during resume.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-nor_11_20-v1-0-70332a54037f@amd.com?part=2

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

      reply	other threads:[~2026-11-20 11:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 11:01 [PATCH 0/2] mtd: spi-nor: Add flash reset support during resume Srikanth Boyapally
2026-11-20 11:01 ` [PATCH 1/2] mtd: spi-nor: Store GPIO info for resetting device " Srikanth Boyapally
2026-11-20 11:01 ` [PATCH 2/2] mtd: spi-nor: Reset flash device on resume Srikanth Boyapally
2026-11-20 11:19   ` sashiko-bot [this message]

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-225022@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=git@amd.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=michal.simek@amd.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=mwalle@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=sai.krishna.potthuri@amd.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=srikanth.boyapally@amd.com \
    --cc=takahiro.kuwano@infineon.com \
    --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