All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Manikandan Muralidharan" <manikandan.m@microchip.com>
Cc: devicetree@vger.kernel.org, "Michael Walle" <mwalle@kernel.org>,
	"Pratyush Yadav" <pratyush@kernel.org>,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Takahiro Kuwano" <takahiro.kuwano@infineon.com>,
	"Richard Weinberger" <richard@nod.at>,
	robh@kernel.org, "Miquel Raynal" <miquel.raynal@bootlin.com>,
	conor+dt@kernel.org
Subject: Re: [PATCH v7 3/7] mtd: spi-nor: sfdp: expose the SFDP as a read-only NVMEM device
Date: Thu, 13 Aug 2026 10:52:00 +0000	[thread overview]
Message-ID: <20260813105200.EFB3A1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260812104955.485667-4-manikandan.m@microchip.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Use-After-Free of device tree node in NVMEM device due to premature of_node_put().
--

--- Patch [3]: [PATCH v7 3/7] mtd: spi-nor: sfdp: expose the SFDP as a read-only NVMEM device ---
commit d892664b27bcd5da338917980297630345d51e30
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 as a read-only NVMEM device
in on-flash byte order. The NVMEM device is registered only when an
sfdp node is present in the device tree.

> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index ccf4396cdcd04..0425af6e898fd 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c

[ ... ]

> @@ -3001,6 +3002,75 @@ static void spi_nor_init_fixup_flags(struct spi_nor *nor)
> +static int spi_nor_register_sfdp_nvmem(struct spi_nor *nor)
> +{

[ ... ]

> +	config.dev = dev;
> +	config.of_node = np;
> +	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;
> +
> +	nvmem = devm_nvmem_register(dev, &config);
> +	of_node_put(np);

[Severity: High]
Does calling of_node_put() here leave the NVMEM device with a dangling
pointer to the device tree node?

The nvmem core assigns config.of_node to the underlying device structure
but does not take an additional reference count on the node itself. 

If a device tree overlay is removed later, causing the node's reference
count to drop to zero, could this lead to a use-after-free when the nvmem
framework or sysfs subsequently accesses the node?

> +	if (IS_ERR(nvmem)) {
> +		/* NVMEM support is optional. */

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260812104955.485667-1-manikandan.m@microchip.com?part=3

  reply	other threads:[~2026-08-13 10:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12 10:49 [PATCH v7 0/7] Read MAC address from SST vendor specific SFDP region Manikandan Muralidharan
2026-08-12 10:49 ` Manikandan Muralidharan
2026-08-12 10:49 ` [PATCH v7 1/7] dt-bindings: mtd: jedec,spi-nor: allow the SFDP to be exposed via NVMEM Manikandan Muralidharan
2026-08-12 10:49   ` Manikandan Muralidharan
2026-08-12 10:49 ` [PATCH v7 2/7] dt-bindings: nvmem: layouts: add Microchip/SST SFDP EUI layout Manikandan Muralidharan
2026-08-12 10:49   ` Manikandan Muralidharan
2026-08-12 10:49 ` [PATCH v7 3/7] mtd: spi-nor: sfdp: expose the SFDP as a read-only NVMEM device Manikandan Muralidharan
2026-08-12 10:49   ` Manikandan Muralidharan
2026-08-13 10:52   ` sashiko-bot [this message]
2026-08-12 10:49 ` [PATCH v7 4/7] nvmem: layouts: add Microchip/SST SFDP EUI layout driver Manikandan Muralidharan
2026-08-12 10:49   ` Manikandan Muralidharan
2026-08-13 10:51   ` sashiko-bot
2026-08-12 10:49 ` [PATCH v7 5/7] ARM: dts: microchip: sama5d27_wlsom1: use fixed-partitions for QSPI flash Manikandan Muralidharan
2026-08-12 10:49   ` Manikandan Muralidharan
2026-08-13 10:51   ` sashiko-bot
2026-08-12 10:49 ` [PATCH v7 6/7] ARM: dts: microchip: sama5d27_wlsom1: read MAC address from QSPI SFDP Manikandan Muralidharan
2026-08-12 10:49   ` Manikandan Muralidharan
2026-08-12 10:49 ` [PATCH v7 7/7] ARM: configs: sama5: enable Microchip/SST SFDP EUI NVMEM layout Manikandan Muralidharan
2026-08-12 10:49   ` 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=20260813105200.EFB3A1F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=manikandan.m@microchip.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=mwalle@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.