[PATCH 2/2] mtd: spi-nor: Reset flash device on resume

sashiko-bot at kernel.org sashiko-bot at kernel.org
Fri Nov 20 03:19:55 PST 2026


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 at 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



More information about the linux-mtd mailing list