Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] mtd/nvmem: don't defer forever on absent NVMEM suppliers
@ 2026-11-30  7:45 Manikandan Muralidharan
  2026-11-30  7:45 ` [PATCH v2 1/2] mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe Manikandan Muralidharan
  2026-11-30  7:45 ` [PATCH v2 2/2] nvmem: core: stop deferring for a cell after the deferred probe timeout Manikandan Muralidharan
  0 siblings, 2 replies; 5+ messages in thread
From: Manikandan Muralidharan @ 2026-11-30  7:45 UTC (permalink / raw)
  To: pratyush, mwalle, takahiro.kuwano, miquel.raynal, richard,
	vigneshr, srini, linux-mtd, linux-kernel
  Cc: manikandan.m

A consumer that gets its MAC address from an NVMEM cell can be deferred
forever when the cell will never appear, instead of falling back to
another address source. These came up while testing the SFDP EUI-48
series [1], where macb reads its MAC address from a cell exposed by the
QSPI flash, but both are generic:

 - 1/2: when the SPI NOR flash is not populated or not reachable, nothing
   below its node is ever registered, yet fw_devlink keeps the consumer
   from probing. Drop the fw_devlink links below a flash that failed to
   probe.

 - 2/2: the NVMEM lookup keeps returning -EPROBE_DEFER for a provider
   that never shows up, or for a cell that a bound layout did not add,
   e.g. when the data it describes is not programmed on the device. Once
   the deferred probe timeout has expired, return -ENOENT instead.

In both cases the consumer then falls back once the deferred probe
timeout has expired (10 seconds by default),
e.g. macb uses the address left by the bootloader or a random one.

This series depends on the SFDP EUI-48 series [1] and applies on top of it.

Changes in v2:
 - 1/2 - Drop the FWNODE_FLAG_NOT_DEVICE check in of_nvmem_cell_get():
         The patch now only touches the SPI NOR core.
 - 2/2 - Replace the "layout is bound" check with a fallback once the
         deferred probe timeout has expired. This covers both the absent
         flash and the missing cell without touching the layout device,
         so it no longer races with the layout probe or removal.
         Renamed from "nvmem: core: don't defer for a missing cell once
         the layout is bound".

v1: https://lore.kernel.org/all/cover.1794391847.git.manikandan.m@microchip.com/

[1] https://lore.kernel.org/all/cover.1796023049.git.manikandan.m@microchip.com/

Manikandan Muralidharan (2):
  mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to
    probe
  nvmem: core: stop deferring for a cell after the deferred probe
    timeout

 drivers/mtd/spi-nor/core.c | 26 +++++++++++++++++++++++++-
 drivers/nvmem/core.c       |  9 +++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)


base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
prerequisite-patch-id: 76d8b1168f88c3e7912ac2ce01a705f7e69d8a3b
prerequisite-patch-id: b360d0d00ac1a6feb76d4b3f9412b6f1741f6161
prerequisite-patch-id: 659801d6f415ba79ce51f21b3a4f5e132348c150
prerequisite-patch-id: 902c67d8bcfad07fc6424ee551557eeab87efaa4
prerequisite-patch-id: 94ede38b6c2480cb1e0e102e9bbeb6ffd5b276ef
prerequisite-patch-id: ae3977b6c56c5bd4f352d77bd8a7883a69d390af
prerequisite-patch-id: 58d0ad25e81f16f60864d624eed7ff481607e960
prerequisite-patch-id: ba140b71fdbfc992861ae4c34b6acc737d4e4528
-- 
2.43.0


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe
  2026-11-30  7:45 [PATCH v2 0/2] mtd/nvmem: don't defer forever on absent NVMEM suppliers Manikandan Muralidharan
@ 2026-11-30  7:45 ` Manikandan Muralidharan
  2026-11-30  8:17   ` sashiko-bot
  2026-11-30  7:45 ` [PATCH v2 2/2] nvmem: core: stop deferring for a cell after the deferred probe timeout Manikandan Muralidharan
  1 sibling, 1 reply; 5+ messages in thread
From: Manikandan Muralidharan @ 2026-11-30  7:45 UTC (permalink / raw)
  To: pratyush, mwalle, takahiro.kuwano, miquel.raynal, richard,
	vigneshr, srini, linux-mtd, linux-kernel
  Cc: manikandan.m

When a SPI NOR flash is not populated or not reachable, spi_nor_scan()
fails and nothing described below the flash node (the SFDP NVMEM device,
its nvmem-layout, partitions) is ever registered. fw_devlink still holds
links from consumers of those nodes, so a consumer such as an Ethernet
MAC whose "nvmem-cells" points at the SFDP EUI-48 cell waits for its
supplier forever and is never probed:

  platform f8008000.ethernet: deferred probe pending: platform: wait for
  supplier /ahb/apb/spi@f0024000/flash@0/sfdp/nvmem-layout/mac-address

On a permanent spi_nor_scan() failure, call
fw_devlink_purge_absent_suppliers() on each child of the flash node to
drop their consumer links, so the consumer is probed. Keep the links on
-EPROBE_DEFER, as the flash may still probe once the reset GPIO or
regulator is available.

Signed-off-by: Manikandan Muralidharan <manikandan.m@microchip.com>
---
 drivers/mtd/spi-nor/core.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 99584ee0ecb3..c2661dc2395b 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -12,6 +12,7 @@
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/errno.h>
+#include <linux/fwnode.h>
 #include <linux/math64.h>
 #include <linux/module.h>
 #include <linux/mtd/mtd.h>
@@ -3624,6 +3625,25 @@ static int spi_nor_create_write_dirmap(struct spi_nor *nor)
 	return PTR_ERR_OR_ZERO(nor->dirmap.wdesc);
 }
 
+/**
+ * spi_nor_purge_absent_suppliers() - drop fw_devlink links below a missing
+ * flash
+ * @dev:	pointer to the flash 'struct device'
+ *
+ * When the flash cannot be probed (e.g. it is not populated or not
+ * reachable), nothing described below its node, such as the SFDP NVMEM
+ * device or the partitions, is ever registered. Mark those nodes as never
+ * becoming devices and drop their consumer links, so that consumers such as
+ * an Ethernet MAC using an NVMEM cell are not deferred forever.
+ */
+static void spi_nor_purge_absent_suppliers(struct device *dev)
+{
+	struct fwnode_handle *child;
+
+	device_for_each_child_node(dev, child)
+		fw_devlink_purge_absent_suppliers(child);
+}
+
 static int spi_nor_probe(struct spi_mem *spimem)
 {
 	struct spi_device *spi = spimem->spi;
@@ -3672,8 +3692,12 @@ static int spi_nor_probe(struct spi_mem *spimem)
 		flash_name = spi->modalias;
 
 	ret = spi_nor_scan(nor, flash_name, &hwcaps);
-	if (ret)
+	if (ret) {
+		/* A deferred probe (e.g. on the reset GPIO) may still succeed. */
+		if (ret != -EPROBE_DEFER)
+			spi_nor_purge_absent_suppliers(dev);
 		return ret;
+	}
 
 	spi_nor_debugfs_register(nor);
 
-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] nvmem: core: stop deferring for a cell after the deferred probe timeout
  2026-11-30  7:45 [PATCH v2 0/2] mtd/nvmem: don't defer forever on absent NVMEM suppliers Manikandan Muralidharan
  2026-11-30  7:45 ` [PATCH v2 1/2] mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe Manikandan Muralidharan
@ 2026-11-30  7:45 ` Manikandan Muralidharan
  1 sibling, 0 replies; 5+ messages in thread
From: Manikandan Muralidharan @ 2026-11-30  7:45 UTC (permalink / raw)
  To: pratyush, mwalle, takahiro.kuwano, miquel.raynal, richard,
	vigneshr, srini, linux-mtd, linux-kernel
  Cc: manikandan.m

nvmem_cell_get() returns -EPROBE_DEFER for as long as the nvmem device
providing a DT cell is not registered. When that device never shows up,
for instance because the flash holding the cell is not populated on the
board, the consumer is deferred forever instead of falling back to
another source.

Once the deferred probe timeout has expired, as reported by
driver_deferred_probe_check_state(), return -ENOENT instead, so that the
consumer treats the cell as missing. A provider that is merely late is
still waited for until then.

Signed-off-by: Manikandan Muralidharan <manikandan.m@microchip.com>
---
 drivers/nvmem/core.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index a755cc4318dc..a1208663b50e 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1508,6 +1508,15 @@ struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id)
 
 	if (dev->of_node) { /* try dt first */
 		cell = of_nvmem_cell_get(dev->of_node, id);
+		/*
+		 * Don't wait forever for a provider that never shows up, e.g.
+		 * when the device holding it is not populated. Once the
+		 * deferred probe timeout has expired, report the cell as
+		 * missing so that the consumer can fall back.
+		 */
+		if (PTR_ERR(cell) == -EPROBE_DEFER &&
+		    driver_deferred_probe_check_state(dev) != -EPROBE_DEFER)
+			return ERR_PTR(-ENOENT);
 		if (!IS_ERR(cell) || PTR_ERR(cell) == -EPROBE_DEFER)
 			return cell;
 	}
-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe
  2026-11-30  7:45 ` [PATCH v2 1/2] mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe Manikandan Muralidharan
@ 2026-11-30  8:17   ` sashiko-bot
  2026-11-30  9:36     ` Manikandan.M
  0 siblings, 1 reply; 5+ messages in thread
From: sashiko-bot @ 2026-11-30  8:17 UTC (permalink / raw)
  To: Manikandan Muralidharan, pratyush, mwalle, takahiro.kuwano,
	miquel.raynal, richard, vigneshr, srini, linux-mtd

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] mtd: spi-nor: missing deferred probe trigger in spi_nor_probe()
  error path
- [Medium] mtd: spi-nor: incomplete supplier purging in spi_nor_probe()
  on error paths
--

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

mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe

This commit calls fw_devlink_purge_absent_suppliers() on child fwnodes of a
SPI NOR flash when spi_nor_scan() fails with a non-deferral error so that
consumers waiting on child nodes are not blocked forever by fw_devlink.

> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 99584ee0ecb32..c2661dc2395bc 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
[ ... ]
> @@ -3624,6 +3625,25 @@ static int spi_nor_create_write_dirmap(struct spi_nor *nor)
>  	return PTR_ERR_OR_ZERO(nor->dirmap.wdesc);
>  }
>  
> +/**
> + * spi_nor_purge_absent_suppliers() - drop fw_devlink links below a missing
> + * flash
> + * @dev:	pointer to the flash 'struct device'
> + *
> + * When the flash cannot be probed (e.g. it is not populated or not
> + * reachable), nothing described below its node, such as the SFDP NVMEM
> + * device or the partitions, is ever registered. Mark those nodes as never
> + * becoming devices and drop their consumer links, so that consumers such as
> + * an Ethernet MAC using an NVMEM cell are not deferred forever.
> + */
> +static void spi_nor_purge_absent_suppliers(struct device *dev)
> +{
> +	struct fwnode_handle *child;
> +
> +	device_for_each_child_node(dev, child)
> +		fw_devlink_purge_absent_suppliers(child);
> +}

[Severity: High]
Does purging the fwnode links on a failed probe wake consumers that are
already on deferred_probe_pending_list?

fw_devlink_purge_absent_suppliers() drops the consumer fwnode links via
fwnode_links_purge_consumers(), which does not call
driver_deferred_probe_trigger().  Because spi_nor_probe() then returns a
non-zero error, really_probe() jumps to probe_failed without calling
driver_bound() or driver_deferred_probe_trigger().

If the consumer already deferred in device_links_check_suppliers() before
spi_nor_probe() ran (for example, when spi-nor or the SPI controller driver
is loaded as a module after the deferred probe timeout, or when the flash is
probed after the consumer during the final deferred_probe_work_func() pass),
nothing moves the consumer from deferred_probe_pending_list to
deferred_probe_active_list unless an unrelated device binds later.

>  static int spi_nor_probe(struct spi_mem *spimem)
>  {
>  	struct spi_device *spi = spimem->spi;
> @@ -3672,8 +3692,12 @@ static int spi_nor_probe(struct spi_mem *spimem)
>  		flash_name = spi->modalias;
>  
>  	ret = spi_nor_scan(nor, flash_name, &hwcaps);
> -	if (ret)
> +	if (ret) {
> +		/* A deferred probe (e.g. on the reset GPIO) may still succeed. */
> +		if (ret != -EPROBE_DEFER)
> +			spi_nor_purge_absent_suppliers(dev);
>  		return ret;
> +	}

[Severity: Medium]
Can spi_nor_purge_absent_suppliers() miss the nvmem-layout child nodes when
spi_nor_scan() fails after registering the SFDP NVMEM device?

Inside spi_nor_scan(), spi_nor_init_params() calls
spi_nor_register_sfdp_nvmem() before spi_nor_late_init_params(),
spi_nor_setup(), spi_nor_init() and spi_nor_set_mtd_info().
spi_nor_register_sfdp_nvmem() uses devm_nvmem_register(), which populates
the nvmem-layout child device and sets fwnode->dev on the nvmem-layout
fwnode via nvmem_layout_create_device().

If a later step in spi_nor_scan() fails, spi_nor_purge_absent_suppliers()
runs before really_probe() calls devres_release_all().  At that point
fwnode->dev is still non-NULL on the nvmem-layout fwnode, so
fw_devlink_purge_absent_suppliers() returns early at the "if (fwnode->dev)
return;" check without purging consumer links on the layout node or
recursing into its child cell nodes (such as mac-address).

Also, if spi_nor_probe() fails with a permanent error outside
spi_nor_scan() (such as in devm_regulator_get_enable(), dirmap creation, or
mtd_device_register()), spi_nor_purge_absent_suppliers() is not called at
all.

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

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe
  2026-11-30  8:17   ` sashiko-bot
@ 2026-11-30  9:36     ` Manikandan.M
  0 siblings, 0 replies; 5+ messages in thread
From: Manikandan.M @ 2026-11-30  9:36 UTC (permalink / raw)
  To: sashiko-reviews, pratyush, mwalle, takahiro.kuwano, miquel.raynal,
	richard, vigneshr, srini, linux-mtd
  Cc: saravanak

Hi,

+Cc Saravana.

On 11/30/26 1:47 PM, sashiko-bot@kernel.org wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [High] mtd: spi-nor: missing deferred probe trigger in spi_nor_probe()
>    error path
> - [Medium] mtd: spi-nor: incomplete supplier purging in spi_nor_probe()
>    on error paths
> --
> 
> commit c60e9abc61b54c89108b300ba9fa15df3cb4bd41
> Author: Manikandan Muralidharan <manikandan.m@microchip.com>
> 
> mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe
> 
> This commit calls fw_devlink_purge_absent_suppliers() on child fwnodes of a
> SPI NOR flash when spi_nor_scan() fails with a non-deferral error so that
> consumers waiting on child nodes are not blocked forever by fw_devlink.
> 
>> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
>> index 99584ee0ecb32..c2661dc2395bc 100644
>> --- a/drivers/mtd/spi-nor/core.c
>> +++ b/drivers/mtd/spi-nor/core.c
> [ ... ]
>> @@ -3624,6 +3625,25 @@ static int spi_nor_create_write_dirmap(struct spi_nor *nor)
>>        return PTR_ERR_OR_ZERO(nor->dirmap.wdesc);
>>   }
>>
>> +/**
>> + * spi_nor_purge_absent_suppliers() - drop fw_devlink links below a missing
>> + * flash
>> + * @dev:     pointer to the flash 'struct device'
>> + *
>> + * When the flash cannot be probed (e.g. it is not populated or not
>> + * reachable), nothing described below its node, such as the SFDP NVMEM
>> + * device or the partitions, is ever registered. Mark those nodes as never
>> + * becoming devices and drop their consumer links, so that consumers such as
>> + * an Ethernet MAC using an NVMEM cell are not deferred forever.
>> + */
>> +static void spi_nor_purge_absent_suppliers(struct device *dev)
>> +{
>> +     struct fwnode_handle *child;
>> +
>> +     device_for_each_child_node(dev, child)
>> +             fw_devlink_purge_absent_suppliers(child);
>> +}
> 
> [Severity: High]
> Does purging the fwnode links on a failed probe wake consumers that are
> already on deferred_probe_pending_list?
> 
Not from spi-nor itself. A consumer that deferred earlier is retried by 
the deferred probe timeout, or by the controller binding when the flash 
is probed from its probe.

> fw_devlink_purge_absent_suppliers() drops the consumer fwnode links via
> fwnode_links_purge_consumers(), which does not call
> driver_deferred_probe_trigger().  Because spi_nor_probe() then returns a
> non-zero error, really_probe() jumps to probe_failed without calling
> driver_bound() or driver_deferred_probe_trigger().
> 
> If the consumer already deferred in device_links_check_suppliers() before
> spi_nor_probe() ran (for example, when spi-nor or the SPI controller driver
> is loaded as a module after the deferred probe timeout, or when the flash is
> probed after the consumer during the final deferred_probe_work_func() pass),
> nothing moves the consumer from deferred_probe_pending_list to
> deferred_probe_active_list unless an unrelated device binds later.
> 
>>   static int spi_nor_probe(struct spi_mem *spimem)
>>   {
>>        struct spi_device *spi = spimem->spi;
>> @@ -3672,8 +3692,12 @@ static int spi_nor_probe(struct spi_mem *spimem)
>>                flash_name = spi->modalias;
>>
>>        ret = spi_nor_scan(nor, flash_name, &hwcaps);
>> -     if (ret)
>> +     if (ret) {
>> +             /* A deferred probe (e.g. on the reset GPIO) may still succeed. */
>> +             if (ret != -EPROBE_DEFER)
>> +                     spi_nor_purge_absent_suppliers(dev);
>>                return ret;
>> +     }
> 
> [Severity: Medium]
> Can spi_nor_purge_absent_suppliers() miss the nvmem-layout child nodes when
> spi_nor_scan() fails after registering the SFDP NVMEM device?
This series targets a flash that is not populated or not reachable, 
which fails before anything below its node is registered. A flash that 
is detected but then fails setup, or fails later in spi_nor_probe(), is 
out of scope.

> 
> Inside spi_nor_scan(), spi_nor_init_params() calls
> spi_nor_register_sfdp_nvmem() before spi_nor_late_init_params(),
> spi_nor_setup(), spi_nor_init() and spi_nor_set_mtd_info().
> spi_nor_register_sfdp_nvmem() uses devm_nvmem_register(), which populates
> the nvmem-layout child device and sets fwnode->dev on the nvmem-layout
> fwnode via nvmem_layout_create_device().
> 
> If a later step in spi_nor_scan() fails, spi_nor_purge_absent_suppliers()
> runs before really_probe() calls devres_release_all().  At that point
> fwnode->dev is still non-NULL on the nvmem-layout fwnode, so
> fw_devlink_purge_absent_suppliers() returns early at the "if (fwnode->dev)
> return;" check without purging consumer links on the layout node or
> recursing into its child cell nodes (such as mac-address).
> 
> Also, if spi_nor_probe() fails with a permanent error outside
> spi_nor_scan() (such as in devm_regulator_get_enable(), dirmap creation, or
> mtd_device_register()), spi_nor_purge_absent_suppliers() is not called at
> all.
> 
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796023057.git.manikandan.m@microchip.com?part=1


-- 
Thanks and Regards,
Manikandan M.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-30  9:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  7:45 [PATCH v2 0/2] mtd/nvmem: don't defer forever on absent NVMEM suppliers Manikandan Muralidharan
2026-11-30  7:45 ` [PATCH v2 1/2] mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe Manikandan Muralidharan
2026-11-30  8:17   ` sashiko-bot
2026-11-30  9:36     ` Manikandan.M
2026-11-30  7:45 ` [PATCH v2 2/2] nvmem: core: stop deferring for a cell after the deferred probe timeout Manikandan Muralidharan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox