Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Pratyush Yadav" <pratyush@kernel.org>,
	"Michael Walle" <mwalle@kernel.org>,
	"Takahiro Kuwano" <takahiro.kuwano@infineon.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Alan Borzeszkowski" <alan.borzeszkowski@linux.intel.com>
Cc: "Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	linux-mtd@lists.infradead.org
Subject: Re: [PATCH] mtd: spi-nor: Report missing SR2 support as -EOPNOTSUPP
Date: Fri, 04 Dec 2026 11:23:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-249668@kernel.org> (raw)
In-Reply-To: <20261204-winbond-upstreaming-fix-sr2-einval-v1-1-ab136bfb2129@bootlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mtd: spi-nor: spi_nor_otp_lock_sr2() clobbers SR2 when
  read_sr2 is unset
--

commit 9454071366aa9e347080887fe00c54b14d0e92c3
Author: Miquel Raynal <miquel.raynal@bootlin.com>

mtd: spi-nor: Report missing SR2 support as -EOPNOTSUPP

This commit changes spi_nor_read_sr2() to return -EOPNOTSUPP instead of
-EINVAL when params->opcodes.read_sr2 is unset, allowing OTP NVMEM
registration to ignore unsupported SR2 reads instead of failing probe.

> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index a04d22d2e2e1c..2374e1f5fadb9 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -842,7 +842,7 @@ int spi_nor_read_sr2(struct spi_nor *nor, u8 *sr2)
>  	struct spi_nor_flash_parameter *params = nor->params;
>  
>  	if (!params->opcodes.read_sr2)
> -		return -EINVAL;
> +		return -EOPNOTSUPP;
>  
>  	return spi_nor_read_sr_ll(nor, params->opcodes.read_sr2, sr2, 1);
>  }

[Severity: Medium]
Does allowing probe to succeed with opcodes.read_sr2 unset expose
spi_nor_otp_lock_sr2() to clobbering SR2?

On Intel SPI and similar controllers that support WRSR without RDCR,
spi_nor_spimem_adjust_hwcaps() clears opcodes.read_sr2 while leaving
write_sr1_and_sr2 and the MTD OTP callbacks active.  Once registered,
OTPLOCK runs spi_nor_otp_lock_sr2() -> spi_nor_read_sr1_and_sr2():

drivers/mtd/spi-nor/core.c:spi_nor_read_sr1_and_sr2() {
    ...
	if (nor->params->opcodes.read_sr2)
		ret = spi_nor_read_sr2(nor, &sr[1]);
	else
		sr[1] = 0;

	return ret;
}

Because sr[1] is synthesized as 0, spi_nor_otp_lock_sr2() writes
sr[1] |= lock_bit via spi_nor_write_sr1_and_sr2_and_check().  That
clears all other non-volatile SR2 bits (such as QE and CMP), skips SR2
read-back verification because opcodes.read_sr2 is 0, and returns 0.

Should spi_nor_otp_lock_sr2() call spi_nor_read_sr1() and
spi_nor_read_sr2() directly (or reject !nor->params->opcodes.read_sr2
with -EOPNOTSUPP) so it fails cleanly like spi_nor_otp_is_locked_sr2()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-winbond-upstreaming-fix-sr2-einval-v1-1-ab136bfb2129@bootlin.com?part=1

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

      reply	other threads:[~2026-12-04 11:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 11:08 [PATCH] mtd: spi-nor: Report missing SR2 support as -EOPNOTSUPP Miquel Raynal
2026-12-04 11:23 ` 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-249668@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alan.borzeszkowski@linux.intel.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=mwalle@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=takahiro.kuwano@infineon.com \
    --cc=thomas.petazzoni@bootlin.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