Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Manikandan Muralidharan" <manikandan.m@microchip.com>,
	pratyush@kernel.org, mwalle@kernel.org,
	takahiro.kuwano@infineon.com, miquel.raynal@bootlin.com,
	richard@nod.at, vigneshr@ti.com, robh@kernel.org,
	krzk+dt@kernel.org, conor+dt@kernel.org, srini@kernel.org,
	nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com,
	claudiu.beznea@tuxon.dev, linux@armlinux.org.uk,
	richardcochran@gmail.com, arnd@arndb.de, linusw@kernel.org,
	enelsonmoore@gmail.com, aaro.koskinen@iki.fi,
	pengpeng@iscas.ac.cn, mathieu.dubois-briand@bootlin.com,
	gregkh@linuxfoundation.org, michael@walle.cc,
	linux-mtd@lists.infradead.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v10 4/8] mtd: spi-nor: sfdp: expose the SFDP as a read-only NVMEM device
Date: Thu, 12 Nov 2026 11:57:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-211057@kernel.org> (raw)
In-Reply-To: <d0cc3945cf8ef204d920efbe776828477bfde469.1794391660.git.manikandan.m@microchip.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] mtd: spi-nor: sfdp: fallback to flash of_node when jedec,sfdp
  node is absent
- [Medium] mtd: spi-nor: sfdp: wrong DT node lookup in
  spi_nor_register_sfdp_nvmem()
- [Medium] mtd: spi-nor: sfdp: missing ignore_wp in
  spi_nor_register_sfdp_nvmem()
--

commit d6b1f5d68968819cd02f25dd18526725661f7542
Author: Manikandan Muralidharan <manikandan.m@microchip.com>

mtd: spi-nor: sfdp: expose the SFDP as a read-only NVMEM device

This commit exposes the cached SFDP table of a SPI NOR flash as a read-only
NVMEM device rooted at the flash's "jedec,sfdp" child node.

> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 90524c58602e1..a034dce7c839e 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c

[ ... ]

> +static int spi_nor_register_sfdp_nvmem(struct spi_nor *nor)
> +{
> +	struct device *dev = nor->dev;
> +	struct nvmem_config config = { };
> +	struct nvmem_device *nvmem;
> +	struct device_node *np;
> +
> +	if (!nor->sfdp)
> +		return 0;
> +
> +	np = of_get_compatible_child(dev_of_node(dev), "jedec,sfdp");

[Severity: Medium]
Should this look up the child node under spi_nor_get_flash_node(nor) instead
of dev_of_node(dev)?

In SPI NOR controller drivers such as hisi-sfc and nxp-spifi, nor->dev is the
controller device while the flash node is a child DT node stored via
spi_nor_set_flash_node().  Using dev_of_node(dev) searches the controller's
DT node and misses the flash's "jedec,sfdp" child node.

> +
> +	config.dev = dev;
> +	config.of_node = np;

[Severity: High]
When the flash DT node has no "jedec,sfdp" child node, np is NULL, but
spi_nor_register_sfdp_nvmem() still registers the NVMEM device with
config.of_node = NULL and config.dev = dev.  In nvmem_register(), a NULL
config->of_node falls back to config->dev->of_node:

drivers/nvmem/core.c:nvmem_register() {
    ...
	if (config->of_node)
		nvmem->dev.of_node = of_node_get(config->of_node);
	else
		nvmem->dev.of_node = of_node_get(config->dev->of_node);
    ...
}

Because spi_nor_register_sfdp_nvmem() runs during spi_nor_scan() before
mtd_device_parse_register() registers the main MTD and OTP NVMEM devices, does
this bind the SFDP NVMEM device to the parent flash DT node first?

On any SPI NOR flash with SFDP whose DT node has no "jedec,sfdp" subnode, the
SFDP NVMEM device claims any nvmem-layout on the flash node (setting
OF_POPULATED_BUS so mtd_nvmem_add() skips it) and shadows the flash MTD and
OTP NVMEM providers in of_nvmem_cell_get() and of_nvmem_device_get(), causing
cell lookups on the flash node to fail or return SFDP bytes instead of flash
data.

If registering without a "jedec,sfdp" subnode is intended, setting
config.no_of_node = !np prevents nvmem_register() from falling back to
dev->of_node.

> +	config.name = "sfdp";
> +	config.id = NVMEM_DEVID_AUTO;
> +	config.owner = THIS_MODULE;
> +	config.read_only = true;
> +	config.word_size = 1;
> +	config.stride = 1;
> +	config.size = (int)(nor->sfdp->num_dwords * sizeof(*nor->sfdp->dwords));
> +	config.reg_read = spi_nor_sfdp_reg_read;
> +	config.priv = nor;

[Severity: Medium]
Does config also need ignore_wp = true, like mtd_nvmem_add() and
mtd_otp_nvmem_register()?

When config.ignore_wp is false, nvmem_register() calls
gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH) even for read-only
providers.  Since the SFDP provider only reads from the cached
nor->sfdp->dwords buffer, leaving ignore_wp unset claims any wp-gpios
property on nor->dev and drives the write-protect line high, or fails probe
with -EBUSY if the GPIO is already claimed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1794391660.git.manikandan.m@microchip.com?part=4

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

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

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 11:55 [PATCH v10 0/8] Read MAC address from SST vendor specific SFDP region Manikandan Muralidharan
2026-11-11 11:55 ` [PATCH v10 1/8] dt-bindings: mtd: jedec,spi-nor: allow the SFDP to be exposed via NVMEM Manikandan Muralidharan
2026-11-11 11:55 ` [PATCH v10 2/8] dt-bindings: nvmem: layouts: add Microchip/SST SFDP EUI layout Manikandan Muralidharan
2026-11-11 11:55 ` [PATCH v10 3/8] nvmem: core: take a reference on dev.of_node in nvmem_register() Manikandan Muralidharan
2026-11-12 11:57   ` sashiko-bot
2026-11-11 11:55 ` [PATCH v10 4/8] mtd: spi-nor: sfdp: expose the SFDP as a read-only NVMEM device Manikandan Muralidharan
2026-11-12 11:57   ` sashiko-bot [this message]
2026-11-11 11:55 ` [PATCH v10 5/8] nvmem: layouts: add Microchip/SST SFDP EUI layout driver Manikandan Muralidharan
2026-11-11 11:55 ` [PATCH v10 6/8] ARM: dts: microchip: sama5d27_wlsom1: use fixed-partitions for QSPI flash Manikandan Muralidharan
2026-11-11 11:55 ` [PATCH v10 7/8] ARM: dts: microchip: sama5d27_wlsom1: read MAC address from QSPI SFDP Manikandan Muralidharan
2026-11-11 11:55 ` [PATCH v10 8/8] ARM: configs: sama5: enable Microchip/SST SFDP EUI NVMEM layout Manikandan Muralidharan

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-211057@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aaro.koskinen@iki.fi \
    --cc=alexandre.belloni@bootlin.com \
    --cc=arnd@arndb.de \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=enelsonmoore@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzk+dt@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=manikandan.m@microchip.com \
    --cc=mathieu.dubois-briand@bootlin.com \
    --cc=michael@walle.cc \
    --cc=miquel.raynal@bootlin.com \
    --cc=mwalle@kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=pengpeng@iscas.ac.cn \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=richardcochran@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=srini@kernel.org \
    --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